/* =========================================================================
   ChatZap — design tokens (claro + escuro)
   ========================================================================= */
:root {
  --primary: #128c7e;
  --primary-hover: #0f766e;
  --on-primary: #ffffff;
  --accent: #25d366;

  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f2f4f6;
  --surface-hover: #eef1f4;
  --border: #e6e8eb;
  --border-strong: #d6dade;

  --text: #111b21;
  --text-2: #5b6b73;

  --chat-bg: #e7e0d8;
  --bubble-in: #ffffff;
  --bubble-out: #d7fdd0;
  --active: #e8f5f1;

  --success: #12a150;
  --error: #ef4444;
  --warning: #f59e0b;

  --ok-bg: #e7f7ef;
  --ok-text: #0a7d55;
  --err-bg: #fdeaea;
  --err-text: #b42318;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;

  --overlay: rgba(17, 27, 33, 0.45);
  --shadow-sm: 0 1px 2px rgba(11, 20, 26, 0.06);
  --shadow-md: 0 6px 20px rgba(11, 20, 26, 0.1);
  --shadow-lg: 0 16px 48px rgba(11, 20, 26, 0.18);

  --skeleton: #e7eaed;
  --skeleton-shine: #f2f4f6;
  --login-grad: linear-gradient(160deg, #128c7e 0%, #075e54 100%);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-full: 999px;

  color-scheme: light;
}

/* Dark: aplicado quando forçado (toggle) OU quando o sistema é escuro
   e o usuário não forçou o claro. */
:root[data-theme="dark"] {
  --primary: #00a884;
  --primary-hover: #06cf9c;
  --on-primary: #05261f;
  --accent: #00a884;

  --bg: #0b141a;
  --surface: #111b21;
  --surface-2: #202c33;
  --surface-hover: #202c33;
  --border: #253138;
  --border-strong: #2a3942;

  --text: #e9edef;
  --text-2: #8696a0;

  --chat-bg: #0b141a;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --active: #2a3942;

  --success: #25d366;
  --error: #f87171;
  --warning: #fbbf24;

  --ok-bg: rgba(0, 168, 132, 0.16);
  --ok-text: #79e0c8;
  --err-bg: rgba(248, 113, 113, 0.16);
  --err-text: #fca5a5;
  --warn-bg: rgba(251, 191, 36, 0.16);
  --warn-text: #fcd34d;

  --overlay: rgba(0, 0, 0, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);

  --skeleton: #1c2830;
  --skeleton-shine: #26333c;
  --login-grad: linear-gradient(160deg, #0b141a 0%, #04231c 100%);

  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #00a884;
    --primary-hover: #06cf9c;
    --on-primary: #05261f;
    --accent: #00a884;
    --bg: #0b141a;
    --surface: #111b21;
    --surface-2: #202c33;
    --surface-hover: #202c33;
    --border: #253138;
    --border-strong: #2a3942;
    --text: #e9edef;
    --text-2: #8696a0;
    --chat-bg: #0b141a;
    --bubble-in: #202c33;
    --bubble-out: #005c4b;
    --active: #2a3942;
    --success: #25d366;
    --error: #f87171;
    --warning: #fbbf24;
    --ok-bg: rgba(0, 168, 132, 0.16);
    --ok-text: #79e0c8;
    --err-bg: rgba(248, 113, 113, 0.16);
    --err-text: #fca5a5;
    --warn-bg: rgba(251, 191, 36, 0.16);
    --warn-text: #fcd34d;
    --overlay: rgba(0, 0, 0, 0.6);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
    --skeleton: #1c2830;
    --skeleton-shine: #26333c;
    --login-grad: linear-gradient(160deg, #0b141a 0%, #04231c 100%);
    color-scheme: dark;
  }
}

/* =========================================================================
   Base
   ========================================================================= */
* {
  box-sizing: border-box;
}
/* utilitário [hidden]: precisa vencer classes que definem display (.nav-item, .thread, .empty…) */
[hidden] {
  display: none !important;
}
::selection {
  background: var(--primary);
  color: var(--on-primary);
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* scrollbars discretas */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-2);
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.app {
  display: grid;
  grid-template-columns: 250px 1fr;
  height: 100vh;
  height: 100dvh;
}

/* =========================================================================
   Sidebar
   ========================================================================= */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 2px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
}
.brand-logo {
  font-size: 22px;
}
.sidebar-toggle {
  margin-left: auto;
}
.sidebar-toggle .ico {
  transition: transform 0.25s ease;
}

/* ----- Sidebar retrátil (desktop; no mobile ela já vira barra inferior) ----- */
@media (min-width: 821px) {
  .app {
    transition: grid-template-columns 0.2s ease;
  }
  .app.sb-collapsed {
    grid-template-columns: 68px 1fr;
  }
  .app.sb-collapsed .sidebar {
    padding: 16px 8px;
  }
  .app.sb-collapsed .brand {
    flex-direction: column;
    gap: 8px;
    padding: 6px 0 14px;
  }
  .app.sb-collapsed .brand-name {
    display: none;
  }
  .app.sb-collapsed .sidebar-toggle {
    margin-left: 0;
  }
  .app.sb-collapsed .sidebar-toggle .ico {
    transform: rotate(180deg);
  }
  /* font-size 0 esconde o rótulo (texto solto); o ícone tem tamanho próprio */
  .app.sb-collapsed .nav-item {
    font-size: 0;
    gap: 0;
    justify-content: center;
    padding: 10px 0;
  }
  .app.sb-collapsed .nav-unread {
    top: 2px;
    right: 6px;
  }
  .app.sb-collapsed .sidebar-user {
    flex-direction: column;
    gap: 8px;
    padding: 10px 0;
  }
  .app.sb-collapsed .me-info {
    display: none;
  }
  .app.sb-collapsed .sidebar-foot {
    justify-content: center;
    padding: 4px 0 0;
  }
  .app.sb-collapsed #conn-label {
    display: none;
  }
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s, transform 0.05s;
}
.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.nav-item:active {
  transform: scale(0.98);
}
.nav-item.is-active {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--shadow-sm);
}
.nav-item .ico {
  width: 20px;
  height: 20px;
}

.sidebar-user {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-top: 1px solid var(--border);
}
.me-info {
  flex: 1;
  min-width: 0;
}
.me-info strong {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.me-info small {
  color: var(--text-2);
  font-size: 12px;
}
.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 0;
  font-size: 12.5px;
  color: var(--text-2);
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: var(--radius-full);
  background: var(--text-2);
}
.dot.ok {
  background: var(--success);
}
.dot.off {
  background: var(--error);
}

.ico {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* =========================================================================
   Content / views
   ========================================================================= */
.content {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.view {
  display: none;
  flex: 1;
  min-height: 0;
  padding: 24px;
  overflow-y: auto;
}
.view.is-active {
  display: flex;
  flex-direction: column;
  animation: view-in 0.22s ease;
}
@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}
.view[data-view="conversations"].is-active {
  padding: 0;
  overflow: hidden;
  animation: none;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.pane-head h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
}
.hint {
  color: var(--text-2);
  font-size: 14px;
  margin: 0 0 16px;
  line-height: 1.5;
}
code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, monospace;
  font-size: 13px;
}

/* =========================================================================
   Conversas
   ========================================================================= */
.convo-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}
.contact-panel {
  display: none;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
}
/* Painel do cliente FIXO só em telas largas (senão estrangula a thread) */
@media (min-width: 1100px) {
  .convo-layout {
    grid-template-columns: 320px minmax(0, 1fr) 380px;
  }
  .contact-panel {
    display: flex;
  }
  #contact-info-btn,
  #contact-panel-close {
    display: none;
  }
}
/* Em telas bem largas o painel ganha ainda mais espaço */
@media (min-width: 1500px) {
  .convo-layout {
    grid-template-columns: 320px minmax(0, 1fr) 460px;
  }
}
/* Abaixo de 1100px o painel é toggle e ocupa a área toda quando aberto */
@media (max-width: 1099px) {
  .convo-layout.showing-contact {
    grid-template-columns: minmax(0, 1fr);
  }
  .convo-layout.showing-contact .convo-list-pane,
  .convo-layout.showing-contact .thread-pane {
    display: none;
  }
  .convo-layout.showing-contact .contact-panel {
    display: flex;
  }
}
.cp-tabbar {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 6px 6px 0;
}
.cp-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.cp-tabs::-webkit-scrollbar {
  display: none;
}
.cp-tab {
  border: none;
  background: none;
  padding: 8px 9px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
}
.cp-tab:hover {
  color: var(--text);
}
.cp-tab.is-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.cp-close {
  flex-shrink: 0;
  align-self: center;
  margin-bottom: 4px;
}
.cp-panels {
  flex: 1;
  min-height: 0;
  position: relative;
}
.cp-panel {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 18px 16px;
}
.cp-panel.is-active {
  display: block;
}
.cp-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.cp-head .avatar.lg {
  width: 72px;
  height: 72px;
  font-size: 26px;
}
.cp-head strong {
  font-size: 16px;
  margin-top: 4px;
}
.cp-head small {
  color: var(--text-2);
  font-size: 13px;
}
.cp-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.cp-section:last-child {
  border-bottom: none;
}
.cp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  font-size: 13.5px;
}
.cp-label {
  color: var(--text-2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}
.cp-value {
  color: var(--text);
  text-align: right;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cp-summary {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
}
.cp-fc-note {
  margin: 8px 0 10px;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.45;
}
.cp-fc-note.err {
  color: var(--error);
}
.cp-fc-hint {
  display: block;
  margin: -4px 0 10px;
  font-size: 11.5px;
  color: var(--text-2);
  opacity: 0.8;
}
.fc-linked {
  font-size: 12px;
  font-weight: 700;
  color: var(--success);
  margin: 6px 0 8px;
}
.fc-nome {
  display: block;
  font-size: 15px;
  margin-bottom: 8px;
}
.fc-resumo {
  margin: 8px 0 4px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
}
.fc-obs {
  padding: 8px 0 4px;
}
.fc-obs p {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.fc-cand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.fc-cand:last-of-type {
  border-bottom: none;
}
.fc-cand-info {
  min-width: 0;
}
.fc-cand-info strong {
  display: block;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fc-cand-info small {
  color: var(--text-2);
  font-size: 12px;
}
.cp-fc-body .ghost-btn {
  margin-top: 8px;
}
.fc-search {
  display: flex;
  gap: 6px;
  margin: 6px 0 10px;
}
.fc-search input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
}
.fc-search .ghost-btn {
  margin-top: 0;
  flex-shrink: 0;
}
.fc-sub {
  padding: 10px 0 2px;
}
.fc-item {
  padding: 7px 9px;
  margin-top: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.fc-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}
.fc-item-top span {
  color: var(--success);
  font-weight: 600;
  flex-shrink: 0;
}
.fc-item small {
  display: block;
  color: var(--text-2);
  font-size: 11.5px;
  margin-top: 2px;
}
.fc-item .fc-posol {
  color: var(--text);
  opacity: 0.85;
  white-space: pre-wrap;
}
.fc-item .ghost-btn {
  margin-top: 8px;
  width: 100%;
}
/* Bloco expansível: fórmulas do orçamento / componentes da receita */
.fc-det {
  margin-top: 6px;
}
.fc-det summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  user-select: none;
}
.fc-det summary:hover {
  text-decoration: underline;
}
.fc-det-list {
  list-style: none;
  margin: 6px 0 2px;
  padding: 0;
}
.fc-det-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 2px 8px;
  padding: 4px 0;
  border-top: 1px dashed var(--border);
  font-size: 12px;
}
.fc-det-list li span {
  color: var(--text);
}
.fc-det-list li em {
  font-style: normal;
  color: var(--text-2);
  flex-shrink: 0;
}
.fc-det-list li small {
  flex-basis: 100%;
  color: var(--text-2);
  font-size: 11px;
}
.cp-tabcontent .cp-fc-note {
  margin: 4px 0 10px;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.45;
}

/* ----- Aba Notas ----- */
.notes-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.notes-form textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text);
  resize: vertical;
}
.notes-form .primary-btn {
  align-self: flex-end;
}
.note-item {
  background: var(--warn-bg);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 8px;
}
.note-item p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-wrap;
}
.note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 5px;
  font-size: 11px;
  color: var(--text-2);
}
.note-del {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 12px;
  opacity: 0.6;
}
.note-del:hover {
  opacity: 1;
}
.convo-list-pane {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.convo-list-pane .pane-head {
  padding: 16px;
  margin: 0;
  border-bottom: 1px solid var(--border);
}
.search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.search-input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-full);
  padding: 9px 16px;
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input::placeholder {
  color: var(--text-2);
}
.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.convo-list {
  overflow-y: auto;
  flex: 1;
}

.convo-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 11px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.convo-item:hover {
  background: var(--surface-hover);
}
.convo-item.is-active {
  background: var(--active);
}
.convo-item .meta {
  flex: 1;
  min-width: 0;
}
.convo-item .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.convo-item .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.convo-item .preview {
  color: var(--text-2);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.convo-item .time {
  font-size: 11px;
  color: var(--text-2);
  flex-shrink: 0;
}
.convo-item.waiting .name {
  font-weight: 700;
}
.convo-item.waiting .time {
  color: var(--accent);
  font-weight: 600;
}
.wait-dot {
  width: 9px;
  height: 9px;
  border-radius: var(--radius-full);
  background: var(--accent);
  flex-shrink: 0;
}

/* Contador de mensagens não lidas (estilo WhatsApp) */
.unread-badge {
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}

.nav-item-rel {
  position: relative;
}

.nav-unread {
  position: absolute;
  top: 4px;
  right: 8px;
  min-width: 17px;
  height: 17px;
  font-size: 10px;
}

/* Cliente pediu um atendente humano (handoff pendente) */
.human-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  /* pulsa para chamar atenção: anel âmbar irradiando do badge */
  animation: human-pulse 1.5s ease-out infinite;
}

@keyframes human-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.55);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(245, 158, 11, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
  }
}

/* acessibilidade: sem animação para quem pediu menos movimento no SO */
@media (prefers-reduced-motion: reduce) {
  .human-badge,
  .sla-flag,
  .suggest-btn.is-loading .ico,
  .skel {
    animation: none;
  }
}

.thread-peer .human-badge {
  margin-left: 8px;
  align-self: center;
}

.human-badge-btn {
  cursor: pointer;
  border: none;
}
.human-badge-btn:hover {
  filter: brightness(0.92);
}

/* ----- Status do atendimento (pill no card + dropdown no thread) ----- */
.status-pill {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  flex-shrink: 0;
}

.sla-flag {
  font-size: 13px;
  flex-shrink: 0;
  filter: hue-rotate(310deg) saturate(4); /* relógio avermelhado */
  animation: sla-pulse 1.6s ease-in-out infinite;
}
@keyframes sla-pulse {
  50% {
    opacity: 0.45;
  }
}

.status-dd {
  position: relative;
}

.status-btn {
  border: 1.5px solid;
  border-radius: var(--radius-full);
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  cursor: pointer;
  white-space: nowrap;
  background: transparent;
  transition: filter 0.15s;
}
.status-btn:hover {
  filter: brightness(0.94);
}

.status-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  min-width: 280px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.status-opt {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}
.status-opt:hover {
  background: var(--active);
}
.status-opt strong {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.status-opt small {
  color: var(--text-2);
  font-size: 12px;
}

/* ----- Configurações: abas ----- */
.settings-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.settings-tab {
  border: none;
  background: none;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.settings-tab:hover {
  color: var(--text);
}
.settings-tab.is-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.settings-panel {
  display: none;
}
.settings-panel.is-active {
  display: block;
}

/* ----- Configurações: editor de status ----- */
.status-config {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.status-cfg-row {
  display: grid;
  grid-template-columns: 44px 180px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.status-cfg-row input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}

.status-cfg-row input[type="text"] {
  min-width: 0;
}

.sla-switch {
  margin: 8px 0 14px;
}

/* ----- Análises (IA categoriza atendimentos) ----- */
.an-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.an-period {
  display: flex;
  gap: 6px;
}

.an-card {
  margin-top: 16px;
}

.an-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.an-bar {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 44px;
  gap: 12px;
  align-items: center;
  padding: 6px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  color: var(--text);
}
.an-bar:hover {
  background: var(--active);
}

.an-bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.an-bar-track {
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--border);
  overflow: hidden;
}

.an-bar-fill {
  display: block;
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--primary), var(--accent));
  min-width: 2px;
  transition: width 0.4s ease;
}

.an-bar-num {
  font-weight: 700;
  text-align: right;
}

.an-drill-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.an-drill-item:hover {
  background: var(--active);
}
.an-drill-item:last-child {
  border-bottom: none;
}

.an-drill-meta {
  flex: 1;
  min-width: 0;
}
.an-drill-meta strong {
  display: block;
  font-size: 14px;
}
.an-drill-meta small {
  color: var(--text-2);
  font-size: 12px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.an-drill-side {
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ----- Linha de badges do card (tag da IA + SLA + atendente) ----- */
.badges-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 5px;
  min-width: 0;
}

/* chip da tag na COR da tag (cor via style inline) */
.tag-chip {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  min-width: 0;
  line-height: 1.6;
}

.badges-row .sla-flag {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--err-bg);
  color: var(--err-text);
  filter: none;
  line-height: 1.6;
}

.badges-row .human-badge {
  font-size: 10.5px;
  padding: 2px 8px;
  line-height: 1.6;
}

/* ----- Configurações > Tags ----- */
.tag-create {
  display: grid;
  grid-template-columns: 44px 240px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin: 12px 0 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.tag-create input[type="color"],
.tag-row input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}

.tag-row {
  grid-template-columns: 44px 240px minmax(0, 1fr) auto;
}

.tag-row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

@media (max-width: 720px) {
  .tag-create,
  .tag-row {
    grid-template-columns: 44px minmax(0, 1fr) auto;
  }
  /* descrição desce pra linha própria; botão/ações ficam na 1ª linha, coluna 3
     (sem isso o auto-placement jogaria o botão na coluna de 44px da cor) */
  .tag-create #tag-new-desc,
  .tag-row .tag-desc {
    grid-column: 1 / -1;
  }
  .tag-create #tag-create-btn,
  .tag-row .tag-row-actions {
    grid-row: 1;
    grid-column: 3;
  }
}

/* editor de categorias (view IA) — key + rótulo + descrição + remover */
.cat-row {
  grid-template-columns: 140px 200px minmax(0, 1fr) auto;
}

@media (max-width: 720px) {
  .an-bar {
    grid-template-columns: 120px minmax(0, 1fr) 36px;
  }
  .cat-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .cat-row .cat-desc {
    grid-column: 1 / -1;
  }
}

.sla-field {
  max-width: 340px;
}

@media (max-width: 720px) {
  .status-cfg-row {
    grid-template-columns: 44px minmax(0, 1fr) auto;
  }
  .status-cfg-row .st-desc {
    grid-column: 1 / -1;
  }
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: linear-gradient(145deg, var(--primary), var(--primary-hover));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}
.avatar.sm {
  width: 34px;
  height: 34px;
  font-size: 13px;
}

/* =========================================================================
   Thread
   ========================================================================= */
.thread-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--chat-bg);
}
.thread {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  min-width: 0;
}
/* Ancora o popover de sugestões acima da barra de citação + composer */
.composer-dock {
  position: relative;
}
.thread-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.thread-peer {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.thread-peer > div {
  min-width: 0;
}
.thread-peer strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread-peer small {
  display: block;
  color: var(--text-2);
}
.thread-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.thread-head .back-btn {
  display: none;
}

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.date-sep {
  align-self: center;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  margin: 10px 0 6px;
  box-shadow: var(--shadow-sm);
}
.bubble {
  max-width: 68%;
  padding: 8px 12px 6px;
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  font-size: 14.2px;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
}
/* só o TEXTO da mensagem preserva quebras de linha — a bolha em si usa
   whitespace normal, senão a indentação do template vira altura fantasma */
.bubble .msg-body {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bubble.inbound {
  align-self: flex-start;
  background: var(--bubble-in);
  border-bottom-left-radius: 5px;
}
.bubble.outbound {
  align-self: flex-end;
  background: var(--bubble-out);
  border-bottom-right-radius: 5px;
}
.bubble .stamp {
  display: block;
  text-align: right;
  font-size: 10.5px;
  color: var(--text-2);
  margin-top: 2px;
}
.bubble.failed {
  background: var(--err-bg);
}

/* ----- Menu de ações da mensagem: bolinha ⋮ ao lado da bolha (estilo WhatsApp) ----- */
.bubble .msg-menu-btn {
  position: absolute;
  top: 3px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* fica FORA da bolha, no lado voltado ao centro do chat (sem sobrepor o texto) */
.bubble.inbound .msg-menu-btn {
  right: -36px;
}
.bubble.outbound .msg-menu-btn {
  left: -36px;
}
.bubble:hover .msg-menu-btn,
.bubble .msg-menu-btn.open {
  opacity: 1;
}
.bubble .msg-menu-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}
/* telas estreitas: sem espaço fora da bolha → volta pro cantinho interno */
@media (max-width: 820px) {
  .bubble.inbound .msg-menu-btn,
  .bubble.outbound .msg-menu-btn {
    left: auto;
    right: 4px;
    width: 24px;
    height: 24px;
    font-size: 14px;
  }
}

.msg-menu {
  position: absolute;
  z-index: 50;
  min-width: 168px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.msg-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
.msg-menu button:hover {
  background: var(--active);
}
.msg-menu button.danger {
  color: var(--error);
}
.msg-menu button .mm-ico {
  color: var(--text-2);
  font-size: 14px;
}
.msg-menu button.danger .mm-ico {
  color: var(--error);
}

/* ----- Citação (reply) dentro da bolha ----- */
.reply-quote {
  display: block;
  margin-bottom: 5px;
  padding: 5px 9px;
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
}
.reply-quote strong {
  display: block;
  color: var(--primary);
  font-size: 11.5px;
  margin-bottom: 1px;
}
.reply-quote .rq-text {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ----- Barra de citação no composer ----- */
.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}
.reply-bar .rb-body {
  flex: 1;
  min-width: 0;
  border-left: 3px solid var(--primary);
  padding-left: 9px;
}
.reply-bar .rb-body strong {
  display: block;
  color: var(--primary);
  font-size: 12px;
}
.reply-bar .rb-body span {
  display: block;
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ----- Tradução inline ----- */
.bubble .translation {
  margin-top: 6px;
  padding: 7px 10px;
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-wrap;
}
.bubble .translation::before {
  content: "🌐 ";
}

/* ----- Mensagem removida (tombstone) ----- */
.bubble.deleted {
  background: var(--surface-2);
  color: var(--text-2);
  font-style: italic;
  box-shadow: none;
}

/* realce ao pular para a mensagem citada */
.bubble.flash {
  animation: bubble-flash 1.2s ease;
}
@keyframes bubble-flash {
  0%,
  40% {
    box-shadow: 0 0 0 3px var(--primary);
  }
  100% {
    box-shadow: var(--shadow-sm);
  }
}
.bubble .err {
  color: var(--error);
  font-size: 11px;
  display: block;
}

.composer {
  display: flex;
  align-items: flex-end; /* botões ficam no fundo quando o textarea cresce */
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  min-width: 0; /* deixa encolher no mobile (senão empurra o send p/ fora) */
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color 0.15s;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.send-btn {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: var(--on-primary);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.06s;
}
.send-btn:hover {
  background: var(--primary-hover);
}
.send-btn:active {
  transform: scale(0.94);
}
.send-btn .ico {
  width: 20px;
  height: 20px;
}
.attach-btn {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.attach-btn:hover {
  background: var(--border);
  color: var(--text);
}
.attach-btn .ico {
  width: 20px;
  height: 20px;
}
/* Botão de sugestão de IA no composer (💡) */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.suggest-btn {
  color: var(--primary);
}
.suggest-btn:hover {
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  color: var(--primary);
}
.suggest-btn.is-loading {
  opacity: 0.6;
  pointer-events: none;
}
.suggest-btn.is-loading .ico {
  animation: spin 0.9s linear infinite;
}

/* Popover de sugestões (aparece acima do composer) */
.suggest-pop {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 100%; /* acima da barra de citação + composer (dock) */
  margin-bottom: 6px;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.suggest-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.suggest-modes {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.suggest-mode {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  padding: 5px 11px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.suggest-mode:hover {
  color: var(--text);
}
.suggest-mode.is-active {
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  border-color: var(--primary);
  color: var(--primary);
}
.suggest-body {
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.suggest-note {
  color: var(--text-2);
  font-size: 13px;
  margin: 6px 2px;
}
.suggest-note.err {
  color: var(--error);
}
.suggest-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 10px 12px;
}
.suggest-item p {
  margin: 0 0 8px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text);
}
.suggest-item-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.suggest-foot {
  display: flex;
  justify-content: flex-end;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
}

/* Bolhas de mídia */
.bubble a {
  color: var(--primary);
}
.bubble img.media-img,
.bubble video.media-img {
  max-width: 260px;
  max-height: 320px;
  border-radius: var(--radius-sm);
  display: block;
  cursor: pointer;
}
.bubble audio {
  max-width: 240px;
  display: block;
}
.bubble .media-doc {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  padding: 4px 0;
}
.bubble .media-doc svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}
.bubble .media-caption {
  margin-top: 4px;
}
.bubble .media-actions {
  display: flex;
  gap: 14px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.bubble .media-link {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
}
.bubble .media-link:hover {
  text-decoration: underline;
}
.bubble .media-link:disabled {
  opacity: 0.6;
  cursor: wait;
  text-decoration: none;
}
.bubble .transcript {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-wrap;
}

/* =========================================================================
   Botões / inputs
   ========================================================================= */
.primary-btn {
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.06s;
}
.primary-btn:hover {
  background: var(--primary-hover);
}
.primary-btn:active {
  transform: scale(0.98);
}
.primary-btn.sm {
  padding: 8px 14px;
  font-size: 14px;
}
.ghost-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}
.ghost-btn:hover {
  background: var(--surface-hover);
  border-color: var(--text-2);
}
.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  padding: 8px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.icon-btn .ico {
  width: 18px;
  height: 18px;
}

/* =========================================================================
   Forms / cards
   ========================================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}
.form-card {
  max-width: 560px;
}
.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field select,
.field input,
.field textarea {
  max-width: 100%;
}
.field > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.field input,
.field textarea,
.field select,
.ai-card select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus,
.field textarea:focus,
.field select:focus,
.ai-card select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}
.field input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.field.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.radio-row {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 14px;
}
.radio-row em {
  color: var(--text-2);
  font-style: normal;
  font-size: 12px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: end;
}
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  align-items: center;
}
.field-note {
  color: var(--text-2);
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius);
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.tab.is-active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.result {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
}
.result.ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}
.result.err {
  background: var(--err-bg);
  color: var(--err-text);
}

/* Switch */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-2);
  user-select: none;
}
.switch input {
  display: none;
}
.switch-track {
  width: 38px;
  height: 22px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  position: relative;
  transition: background 0.2s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: var(--radius-full);
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.switch input:checked + .switch-track {
  background: var(--accent);
}
.switch input:checked + .switch-track::after {
  transform: translateX(16px);
}

/* Toggle da IA no composer (ao lado do clipe de anexo) */
.ia-switch {
  align-self: center;
  flex-shrink: 0;
  gap: 6px;
  padding: 0 2px;
}
.ia-switch .ia-ico {
  width: 20px;
  height: 20px;
  fill: currentColor;
  stroke: none;
  color: var(--text-2);
  transition: color 0.2s;
}
.ia-switch.ia-on .ia-ico {
  color: var(--accent);
}

/* Botão "Resumir" no header */
.summary-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.summary-btn .ia-ico {
  width: 16px;
  height: 16px;
  fill: currentColor;
  stroke: none;
  color: var(--primary);
}

/* Faixa "Análise IA" fixa no topo da conversa (não é popup) */
.ai-banner {
  flex-shrink: 0;
  padding: 10px 16px 12px;
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
  border-bottom: 1px solid var(--border);
}
.ai-banner-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.ai-banner-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  flex-shrink: 0;
}
.ai-banner-title .ia-ico {
  width: 16px;
  height: 16px;
  fill: currentColor;
  stroke: none;
}
.ai-banner-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.ai-banner-chips .ai-sent {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: capitalize;
}
.ai-banner-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.ai-banner-btn {
  width: 26px;
  height: 26px;
  font-size: 14px;
}
.ai-banner-body {
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 13.5px;
  color: var(--text);
  max-height: 40vh;
  overflow-y: auto;
}
.ai-banner-body.loading {
  color: var(--text-2);
}
.ai-banner-body.err {
  color: var(--error);
}

/* =========================================================================
   Regras / usuários (linhas)
   ========================================================================= */
.rules-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 780px;
}
.rule,
.user-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.rule:hover,
.user-row:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--border-strong);
}
.rule.disabled {
  opacity: 0.55;
}
.rule .kw {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.rule .reply {
  flex: 1;
  color: var(--text-2);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rule .prio {
  font-size: 12px;
  color: var(--text-2);
}
.rule .rule-actions,
.user-row .rule-actions {
  display: flex;
  gap: 6px;
}
.user-row .avatar {
  width: 40px;
  height: 40px;
}
.user-row .u-meta {
  flex: 1;
  min-width: 0;
}
.user-row .u-meta strong {
  display: block;
}
.user-row .u-meta small {
  color: var(--text-2);
}
.role-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-2);
}
.role-tag.admin {
  background: var(--active);
  color: var(--primary-hover);
}

/* =========================================================================
   Dashboard
   ========================================================================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  max-width: 860px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s, box-shadow 0.15s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.stat-card .num {
  font-size: 34px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
}
.stat-card .label {
  color: var(--text-2);
  font-size: 13px;
  margin-top: 4px;
}

/* =========================================================================
   Settings / IA
   ========================================================================= */
.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  max-width: 960px;
}
.card-title {
  margin: 0 0 4px;
  font-size: 16px;
}
.cred-view {
  margin: 8px 0 4px;
  display: flex;
  flex-direction: column;
}
.cred-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cred-row:last-child {
  border-bottom: none;
}
.cred-row dt {
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
}
.cred-row dd {
  margin: 0;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
  text-align: right;
}
.copy-row {
  display: flex;
  gap: 8px;
}
.copy-row input {
  flex: 1;
  font-family: ui-monospace, monospace;
  font-size: 13px;
}
.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-2);
}
.badge.ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}
.badge.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}
.ai-card {
  max-width: 780px;
  margin-bottom: 24px;
}
.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.ai-card .form {
  margin-top: 12px;
}

/* Menu IA */
.ai-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  max-width: 1100px;
}
.ai-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}
.ai-savebar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
  max-width: 1100px;
}
input[type="range"] {
  accent-color: var(--primary);
  width: 100%;
}
.play-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--chat-bg);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 90px;
}
.play-log:empty::before {
  content: "Nenhuma mensagem ainda — mande uma pergunta abaixo 👇";
  color: var(--text-2);
  font-size: 13px;
  margin: auto;
  text-align: center;
}
.play-bubble {
  max-width: 88%;
  padding: 7px 11px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: var(--shadow-sm);
}
.play-bubble.user {
  align-self: flex-end;
  background: var(--bubble-out);
}
.play-bubble.bot {
  align-self: flex-start;
  background: var(--bubble-in);
}
.play-bubble.err {
  align-self: flex-start;
  background: var(--err-bg);
  color: var(--err-text);
}
@media (max-width: 900px) {
  .ai-grid {
    grid-template-columns: 1fr;
  }
}

/* Templates */
.tpl-card {
  max-width: 980px;
}
.tpl-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.tpl-row .tpl-meta {
  flex: 1;
  min-width: 0;
}
.tpl-row .tpl-name {
  font-weight: 600;
  font-family: ui-monospace, monospace;
  font-size: 14px;
  word-break: break-all;
}
.tpl-row .tpl-sub {
  color: var(--text-2);
  font-size: 12px;
  margin-top: 2px;
}
.tpl-status {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.tpl-status.approved {
  background: var(--ok-bg);
  color: var(--ok-text);
}
.tpl-status.pending {
  background: var(--warn-bg);
  color: var(--warn-text);
}
.tpl-status.rejected {
  background: var(--err-bg);
  color: var(--err-text);
}
.tpl-actions-row {
  margin-top: 14px;
}
/* Construtor de template */
.tpl-builder {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}
.tpl-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.tpl-builder-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.tpl-builder > #tpl-result {
  grid-column: 1 / -1;
}
.tpl-quickstart {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.chip {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  border-radius: var(--radius-full);
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.chip:hover {
  background: var(--surface-hover);
  border-color: var(--primary);
}
.chip.sm {
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
}
.tpl-body-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.tpl-body-head > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.tpl-body-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tpl-vars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tpl-var-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tpl-var-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}
.tpl-varchip {
  display: inline-block;
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  color: var(--primary-hover);
  border-radius: var(--radius-sm);
  padding: 1px 7px;
  font-family: ui-monospace, monospace;
  font-size: 12.5px;
  font-weight: 600;
}
.tpl-varchip.empty {
  background: var(--surface-2);
  color: var(--text-2);
}
.tpl-preview-pane {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 8px;
}
.wa-preview {
  background: var(--chat-bg);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
}
.wa-bubble {
  background: var(--bubble-in);
  border-radius: var(--radius);
  border-top-left-radius: 3px;
  padding: 8px 10px 6px;
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  line-height: 1.45;
  max-width: 100%;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.wa-header {
  font-weight: 700;
  margin-bottom: 3px;
}
.wa-footer {
  color: var(--text-2);
  font-size: 12.5px;
  margin-top: 5px;
}
.wa-time {
  display: block;
  text-align: right;
  font-size: 10.5px;
  color: var(--text-2);
  margin-top: 3px;
}
@media (max-width: 900px) {
  .tpl-builder {
    grid-template-columns: 1fr;
  }
  .tpl-preview-pane {
    position: static;
  }
}

/* =========================================================================
   Empty state / skeleton
   ========================================================================= */
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-2);
  text-align: center;
  padding: 40px 16px;
}
.empty-ico {
  font-size: 46px;
  opacity: 0.9;
}

.skel {
  background: linear-gradient(
    90deg,
    var(--skeleton) 25%,
    var(--skeleton-shine) 37%,
    var(--skeleton) 63%
  );
  background-size: 400% 100%;
  animation: skel 1.3s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skel {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}
.skel-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.skel-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.skel-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.skel-line {
  height: 11px;
}

/* =========================================================================
   Modal / toast
   ========================================================================= */
.modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
  animation: fade 0.15s ease;
}
.modal[hidden] {
  display: none;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: min(480px, 100%);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}
.modal-card h3 {
  margin: 0 0 16px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  font-size: 14px;
  font-weight: 500;
  max-width: min(90vw, 460px);
  animation: toast-in 0.2s ease;
}
.toast.err {
  background: var(--error);
  color: #fff;
}
.toast[hidden] {
  display: none;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
}

/* =========================================================================
   Login
   ========================================================================= */
.login-page {
  background: var(--login-grad);
}
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(400px, 100%);
  padding: 34px;
  box-shadow: var(--shadow-lg);
}
.login-brand {
  text-align: center;
  margin-bottom: 24px;
}
.login-brand h1 {
  margin: 8px 0 4px;
  font-size: 25px;
}
.login-brand p {
  margin: 0;
  color: var(--text-2);
  font-size: 14px;
}
.login-brand .brand-logo {
  font-size: 42px;
}
.login-btn {
  width: 100%;
  padding: 12px;
  margin-top: 4px;
}
.login-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

/* Atribuição */
.assign-select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  max-width: 150px;
}

/* =========================================================================
   Responsivo — mobile
   ========================================================================= */
@media (max-width: 820px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .form-row {
    grid-template-columns: 1fr;
  }

  /* cabeçalho da conversa: controles compactos, sem estourar a largura */
  .thread-head .switch-label {
    display: none;
  }
  .status-btn {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .status-menu {
    max-width: calc(100vw - 24px);
  }

  /* sidebar vira barra inferior */
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .sidebar {
    grid-row: 2;
    flex-direction: row;
    align-items: center;
    padding: 4px 6px;
    gap: 2px;
    border-right: none;
    border-top: 1px solid var(--border);
    overflow-x: auto;
  }
  .brand,
  .sidebar-foot,
  .sidebar-user .me-info,
  .sidebar-user #me-avatar {
    display: none;
  }
  .nav {
    flex-direction: row;
    flex: 1;
    justify-content: space-around;
    gap: 0;
  }
  .nav-item {
    flex-direction: column;
    gap: 3px;
    padding: 7px 6px;
    font-size: 10.5px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    min-width: 56px;
  }
  .nav-item.is-active {
    background: transparent;
    color: var(--primary);
    box-shadow: none;
  }
  .nav-item .ico {
    width: 23px;
    height: 23px;
  }
  .sidebar-user {
    margin: 0;
    border-top: none;
    padding: 4px;
    gap: 2px;
  }

  /* conversas: lista OU thread */
  .convo-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .thread-pane {
    display: none;
  }
  .convo-layout.showing-thread .convo-list-pane {
    display: none;
  }
  .convo-layout.showing-thread .thread-pane {
    display: flex;
  }
  /* painel toggle (overlay) já tratado no @media (max-width: 1099px) */
  .thread-head {
    gap: 8px;
    padding: 8px 12px;
  }
  .thread-head .back-btn {
    display: grid;
  }
  .thread-actions {
    gap: 8px;
  }
  /* enxuga o cabeçalho no mobile: esconde o botão "Encerrar" (fica no desktop) */
  .thread-actions .ghost-btn {
    display: none;
  }
  .assign-select {
    max-width: 116px;
  }
  .bubble {
    max-width: 84%;
  }
  .view {
    padding: 18px 16px;
  }
}
