:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --line: #d9e1ec;
  --text: #17202f;
  --muted: #667085;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #2563eb;
  --danger: #b42318;
  --ok: #067647;
}

/* Elementos ocultados pela busca e pelos filtros devem prevalecer sobre
   componentes que definem display (grid, flex etc.). */
[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .crm-filters {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .crm-filters {
    grid-template-columns: 1fr;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  background: #15202b;
  color: #eef2f7;
  padding: 24px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 36px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--primary);
  font-weight: 800;
}

.brand small {
  display: block;
  color: #aeb7c5;
  margin-top: 2px;
}

nav {
  display: grid;
  gap: 6px;
}

nav a,
.logout-form button {
  color: #d6dde8;
  padding: 11px 12px;
  border-radius: 8px;
}

nav a:hover,
.logout-form button:hover {
  background: #223142;
  color: #fff;
}

.logout-form {
  margin: 0;
}

.logout-form button {
  width: 100%;
  min-height: 0;
  justify-content: flex-start;
  border: 0;
  background: transparent;
  font-weight: 400;
}

.content {
  margin-left: 248px;
  padding: 32px;
}

.chat-page {
  overflow: hidden;
}

.chat-page .content {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-page .content > .page-header {
  flex: 0 0 auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

.button,
button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  font: inherit;
  font-weight: 700;
}

.button.primary,
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.button.primary:hover,
button.primary:hover {
  background: var(--primary-dark);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metrics.dashboard-metrics {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  padding: 22px;
}

.metric span,
.muted {
  color: var(--muted);
}

.metric strong {
  display: block;
  font-size: 30px;
  margin-top: 10px;
}

.panel {
  margin-bottom: 18px;
  padding: 18px;
}

.grid.two-columns {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 18px;
}

.actions {
  display: flex;
  gap: 10px;
}

.crm-filters {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(160px, 1fr) minmax(180px, 1fr) auto auto;
  align-items: end;
  gap: 12px;
}

.crm-filters > div {
  display: grid;
  gap: 6px;
}

.crm-filters label {
  font-size: 13px;
  font-weight: 700;
}

.compact-header {
  margin-bottom: 8px;
}

.table-scroll {
  overflow-x: auto;
}

.crm-nav { align-items: center; border-bottom: 1px solid var(--line); display: flex; gap: 24px; margin-bottom: 20px; }
.crm-nav a { color: var(--muted); padding: 10px 2px; text-decoration: none; }
.crm-nav a.active { border-bottom: 3px solid var(--primary); color: var(--text); font-weight: 700; }
.crm-metrics { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
.crm-metrics .metric strong { font-size: 22px; }
.crm-filters { margin-bottom: 18px; padding: 14px 18px; }
.crm-filters summary, .crm-report-details > summary { cursor: pointer; font-weight: 700; }
.crm-filters form { align-items: end; display: flex; flex-wrap: wrap; gap: 12px; padding-top: 16px; }
.crm-filters label { display: grid; gap: 5px; min-width: 150px; }
.crm-report-details { margin-top: 20px; }
.crm-report-details > summary { padding: 4px; }
.crm-secondary-metrics { grid-template-columns: repeat(5, minmax(140px, 1fr)); margin-top: 18px; }
.crm-reports { margin-top: 14px; }
.crm-customer-details dl { display: grid; gap: 20px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; }
.crm-customer-details dl > div { border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.crm-customer-details dl > div.full { grid-column: 1 / -1; }
.crm-customer-details dt, .crm-locked-fields span { color: var(--muted); font-size: 13px; margin-bottom: 5px; }
.crm-customer-details dd { font-size: 16px; margin: 0; }
.crm-locked-fields { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; display: grid; gap: 16px; grid-template-columns: 1fr 1fr; margin-bottom: 12px; padding: 16px; }
.crm-locked-fields div { display: grid; gap: 4px; }
.kanban { display: flex; gap: 14px; overflow-x: auto; align-items: flex-start; padding-bottom: 18px; }
.kanban-column { background: #eef2f6; border-radius: 8px; flex: 0 0 300px; min-height: 280px; }
.kanban-column > header { border-top: 4px solid; display: flex; justify-content: space-between; padding: 12px; }
.kanban-column > header span { color: var(--muted); font-size: 12px; }
.kanban-dropzone { min-height: 220px; padding: 8px; }
.kanban-card { background: white; border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 8px; display: grid; gap: 7px; margin-bottom: 9px; padding: 12px; }
.kanban-card.priority-alta { border-left-color: #f97316; }
.kanban-card.priority-urgente { border-left-color: #dc2626; }
.crm-tag { background: color-mix(in srgb, var(--tag-color) 15%, white); border: 1px solid var(--tag-color); border-radius: 999px; color: var(--tag-color); display: inline-block; font-size: 11px; margin: 2px; padding: 2px 7px; }

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

.form-panel p,
.filters {
  display: grid;
  gap: 6px;
}

.form-panel label {
  font-weight: 700;
}

.form-panel .helptext {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.form-panel input[type="checkbox"] {
  width: auto;
  justify-self: start;
}

.setup-guide {
  margin-bottom: 18px;
}

.guide-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 20px;
}

.guide-grid p {
  color: var(--muted);
  margin: 8px 0;
}

.guide-grid ul {
  margin: 0;
  padding-left: 18px;
}

.guide-grid li {
  margin: 7px 0;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 8px;
  background: #eef2f7;
  color: #344054;
}

.badge.enviado,
.badge.em_atendimento {
  background: #ecfdf3;
  color: var(--ok);
}

.badge.erro {
  background: #fef3f2;
  color: var(--danger);
}

.badge.novo,
.badge.recebido {
  background: #eff6ff;
  color: #1d4ed8;
}

.badge.transferido {
  background: #f3e8ff;
  color: #7e22ce;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px 14px;
}

.review-mode-banner {
  align-items: center;
  background: #fffaeb;
  border: 1px solid #fedf89;
  border-radius: 10px;
  color: #7a2e0e;
  display: flex;
  font-size: 13px;
  font-weight: 600;
  gap: 8px;
  margin-bottom: 18px;
  padding: 9px 12px;
}

.status-dot {
  background: #f79009;
  border-radius: 999px;
  box-shadow: 0 0 0 3px #fef0c7;
  display: inline-block;
  height: 8px;
  width: 8px;
}

.message-template-layout {
  align-items: start;
}

.account-summary dl {
  display: grid;
  gap: 4px;
  margin: 20px 0;
}

.account-summary dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-top: 10px;
  text-transform: uppercase;
}

.account-summary dd {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  overflow-wrap: anywhere;
}

.message-template-tip {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: grid;
  gap: 5px;
  padding: 14px;
}

.message-template-tip span {
  color: var(--muted);
  font-size: 13px;
}

.message.success {
  background: #ecfdf3;
  border-color: #abefc6;
  color: var(--ok);
}

.message.error {
  background: #fef3f2;
  border-color: #fecdca;
  color: var(--danger);
}

.chat-layout {
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 340px;
  gap: 18px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.seller-chat-layout {
  grid-template-columns: minmax(260px, 340px) minmax(360px, 1fr);
}

.conversation-list,
.client-panel,
.chat-panel {
  margin-bottom: 0;
  min-height: 0;
  overflow: auto;
}

.conversation-item {
  border-bottom: 1px solid var(--line);
  color: var(--text);
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  position: relative;
  padding: 12px 8px;
}

.conversation-copy { display: grid; gap: 3px; min-width: 0; }
.conversation-line { align-items: baseline; display: flex; gap: 8px; justify-content: space-between; }
.conversation-preview-line { align-items: center; display: flex; gap: 8px; min-width: 0; }
.conversation-line strong, .conversation-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-preview { flex: 1 1 auto; min-width: 0; }
.conversation-line time { color: var(--muted); flex: 0 0 auto; font-size: 11px; }
.conversation-item.unread .conversation-line time { color: #00a884; font-weight: 700; }
.conversation-preview-status { color: #667781 !important; flex: 0 0 auto; font-size: 12px; font-weight: 800; }
.conversation-preview-status.read { color: #53bdeb !important; }
.conversation-preview-status.failed { color: var(--danger) !important; }
.chat-avatar { align-items: center; align-self: center; background: #dfe7ec; border-radius: 999px; color: #52606d; display: inline-flex; flex: 0 0 auto; font-size: 18px; font-weight: 800; height: 44px; justify-content: center; width: 44px; }
.chat-avatar img { border-radius: inherit; height: 100%; object-fit: cover; width: 100%; }
.header-avatar { height: 40px; width: 40px; }
.chat-contact-title { min-width: 0; }
.chat-search { align-items: center; display: flex; position: relative; }
.chat-search svg { fill: none; height: 18px; left: 12px; pointer-events: none; position: absolute; stroke: var(--muted); stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; width: 18px; z-index: 1; }
.chat-search input { background: #f0f2f5; border: 0; border-radius: 8px; min-height: 36px; padding-left: 40px; width: 100%; }
.chat-filters { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0; scrollbar-width: none; }
.chat-filters::-webkit-scrollbar { display: none; }
.chat-filters button { border-radius: 999px; min-height: 30px; padding: 0 13px; }
.chat-filters button.active { background: #00a884; border-color: #00a884; color: #fff; }
.notification-enable { background: transparent; border: 0; color: #008f72; font-size: 12px; min-height: 30px; padding: 3px 0; text-align: left; }
.notification-enable:disabled { color: var(--muted); cursor: default; opacity: 1; }

.in-app-notification {
  background: #fff;
  border: 1px solid #d9e1ec;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .3);
  color: #111b21;
  align-items: center;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 3px;
  left: 50%;
  max-width: min(420px, calc(100% - 24px));
  padding: 12px 15px;
  position: fixed;
  text-decoration: none;
  top: max(12px, env(safe-area-inset-top));
  transform: translateX(-50%);
  width: calc(100% - 24px);
  z-index: 1200;
}
.in-app-notification strong { color: #111b21; }
.notification-copy { display: grid; gap: 3px; min-width: 0; }
.notification-preview { color: #667781; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notification-avatar { align-items: center; background: #dfe7ec; border-radius: 999px; color: #52606d; display: flex; font-size: 18px; font-weight: 800; height: 40px; justify-content: center; overflow: hidden; width: 40px; }
.notification-avatar img { height: 100%; object-fit: cover; width: 100%; }

.conversation-item.active {
  background: #f0fdfa;
  border-radius: 8px;
}

.conversation-item span,
.conversation-item small {
  color: var(--muted);
}

/* Hierarquia visual da lista, como no WhatsApp: contato em destaque e
   informacoes secundarias em cinza. Esta regra precisa vir depois da regra
   generica de spans para o nome nao herdar a cor da previa. */
.conversation-item .conversation-line strong {
  color: #111b21;
}

.conversation-item .conversation-preview {
  color: #667781;
}

.conversation-item.unread {
  background: #f0fdfa;
  border-left: 4px solid #00a884;
  padding-left: 10px;
}

.conversation-item.unread strong {
  font-weight: 900;
}

.conversation-item.unread > span:first-of-type {
  color: var(--text);
  font-weight: 800;
}

.unread-count {
  background: #00a884;
  border-radius: 999px;
  color: #fff !important;
  font-size: 10px;
  flex: 0 0 auto;
  height: 18px;
  line-height: 18px;
  min-width: 18px;
  padding: 0 5px;
  text-align: center;
}

.conversation-state { display: flex; gap: 7px; }
.conversation-state.is-empty { display: none; }
.favorite-label { color: #00a884 !important; font-weight: 700; }
.conversation-filter-empty { padding: 24px 10px; text-align: center; }

.favorite-chat-menu {
  align-items: end;
  background: rgba(0, 0, 0, .48);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 16px;
  position: fixed;
  z-index: 1000;
}

.favorite-chat-menu-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .25);
  display: grid;
  gap: 8px;
  max-width: 420px;
  padding: 18px;
  width: 100%;
}

.favorite-chat-menu-card strong { color: var(--text); padding: 2px 4px 10px; }
.favorite-chat-menu-card button { min-height: 44px; width: 100%; }
.favorite-chat-toggle { background: #00a884; border-color: #00a884; color: #fff; }
.chat-close-service { color: var(--danger); }

.conversation-item .badge {
  justify-self: start;
}

.conversation-item > .badge.transferido { display: none; }

.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  position: relative;
}

.new-messages-button { background: var(--surface); border-radius: 999px; bottom: 78px; box-shadow: 0 3px 12px rgba(0,0,0,.18); color: var(--primary); left: 50%; min-height: 34px; padding: 0 14px; position: absolute; transform: translateX(-50%); z-index: 5; }
.new-messages-button[hidden] { display: none; }

.chat-header,
.status-form,
.reply-form {
  display: flex;
  gap: 10px;
}

.chat-header {
  align-items: center;
  justify-content: space-between;
}

.chat-message-search-toggle { flex: 0 0 auto; }
.message-search { align-items: center; background: var(--surface); display: flex; gap: 8px; padding: 8px 12px; }
.message-search[hidden] { display: none; }
.message-search input { flex: 1 1 auto; min-height: 36px; }
.message-search button { border: 0; font-size: 22px; min-height: 34px; padding: 0 10px; }

.chat-date-separator { display: flex; justify-content: center; margin: 4px 0; width: 100%; }
.chat-date-separator span { background: #fff; border-radius: 7px; box-shadow: 0 1px 1px rgba(0,0,0,.08); color: var(--muted); font-size: 11px; padding: 6px 10px; }

.handoff-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.handoff-meta small {
  color: var(--muted);
  font-weight: 600;
}

.messages-thread {
  background-color: #efeae2;
  background-image: url("../core/chat-wallpaper-light.08fcb6cd628e.svg");
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 14px;
  scroll-behavior: smooth;
}

.chat-layout[data-scroll-state="loading"] .messages-thread {
  opacity: 0;
  visibility: hidden;
}

.chat-layout[data-scroll-state="ready"] .messages-thread {
  opacity: 1;
  visibility: visible;
}

.messages-thread::before {
  content: "";
  margin-top: auto;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: 9px;
  display: grid;
  gap: 6px;
  max-width: 78%;
  padding: 10px 12px;
}

.bubble.entrada {
  align-self: flex-start;
  background: #fff;
}

.bubble.saida {
  align-self: flex-end;
  background: #dcfce7;
  border-color: #bbf7d0;
}

.bubble.entrada + .bubble.entrada, .bubble.saida + .bubble.saida { margin-top: -6px; }

.bubble small {
  color: var(--muted);
  font-size: 12px;
}

.message-meta {
  align-items: center;
  display: inline-flex;
  gap: 6px;
  justify-content: flex-end;
}

.client-panel details > summary { cursor: pointer; font-weight: 800; margin-bottom: 14px; }

.message-status {
  color: #64748b;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.message-status.read {
  color: #0ea5e9;
}

.message-status.failed {
  color: #dc2626;
}

.message-status.pending {
  color: #64748b;
}

.bubble.pending {
  opacity: 0.82;
}

.bubble.failed {
  border-color: #fecaca;
}

.composer {
  display: grid;
  flex: 1 1 auto;
  gap: 8px;
}

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

.attachment-menu { position: relative; }
.attachment-menu > summary { list-style: none; }
.attachment-menu > summary::-webkit-details-marker { display: none; }
.attachment-menu > div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; bottom: 48px; box-shadow: 0 5px 20px rgba(0,0,0,.18); display: grid; gap: 4px; left: 0; min-width: 170px; padding: 8px; position: absolute; z-index: 8; }
.attachment-menu .attach-button { justify-content: flex-start; width: 100%; }
.quick-replies-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; bottom: 76px; display: grid; gap: 6px; left: 12px; max-height: 280px; overflow: auto; padding: 8px; position: absolute; width: min(390px, calc(100% - 24px)); z-index: 7; }
.quick-replies-panel[hidden] { display: none; }
.quick-replies-panel button { align-items: flex-start; display: grid; gap: 2px; justify-content: stretch; min-height: 48px; padding: 8px 10px; text-align: left; }
.quick-replies-panel button span { color: var(--muted); font-size: 12px; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-button {
  align-items: center;
  background: transparent;
  border: 0;
  display: inline-flex;
  height: 36px;
  justify-content: center;
  min-width: 36px;
  padding: 0;
  width: 36px;
}

.icon-button:hover,
.icon-button:focus-visible,
.back-to-list:hover,
.back-to-list:focus-visible {
  background: rgba(100, 116, 139, 0.14);
  border: 0;
  outline: none;
}

.icon-button svg,
.send-button svg {
  fill: none;
  height: 20px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 20px;
}

.send-button svg {
  fill: currentColor;
  stroke-width: 1.5;
}

.camera-button,
.gallery-button,
.document-button,
.mic-button {
  border-radius: 999px;
  font-size: 16px;
}

.menu-item {
  justify-content: flex-start;
  min-height: 36px;
  width: 100%;
}

.attach-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.back-to-list {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  display: none;
  font-size: 13px;
  font-weight: 800;
  min-height: 34px;
  padding: 0 10px;
}

.attachment-input {
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  position: absolute;
  width: 1px;
}

.form-errors {
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  font-size: 13px;
  grid-column: 1 / -1;
  padding: 8px 10px;
}

.form-errors ul {
  margin: 0;
  padding-left: 18px;
}

.attachment-status {
  min-height: 18px;
  font-size: 12px;
}

.reply-form textarea {
  max-height: 132px;
  min-height: 42px;
  overflow-y: auto;
  resize: none;
}

.send-button {
  align-self: end;
  background: var(--primary);
  border: 0;
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  height: 42px;
  justify-content: center;
  min-height: 42px;
  min-width: 42px;
  padding: 0;
  width: 42px;
}

.send-button:hover {
  background: var(--primary-dark);
}

.send-button:disabled,
.send-button.is-sending {
  cursor: wait;
  opacity: 0.65;
}

.send-button span {
  display: block;
  font-size: 18px;
  line-height: 1;
  transform: translateX(1px);
}

.message-media {
  border-radius: 8px;
  display: block;
  max-height: 260px;
  max-width: 100%;
  object-fit: contain;
}

.message-media-link {
  display: block;
  max-width: min(320px, 100%);
}

.message-media-link .message-media {
  width: 100%;
}

.image-preview-modal {
  align-items: center;
  background: rgba(15, 23, 42, 0.92);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  padding: 18px;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 1000;
}

.image-preview-modal[hidden] {
  display: none;
}

.image-preview-content {
  border-radius: 8px;
  max-height: 92vh;
  max-width: 96vw;
  object-fit: contain;
}

.image-preview-close {
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  border: 0;
  border-radius: 999px;
  color: var(--text);
  display: inline-flex;
  font-size: 28px;
  font-weight: 700;
  height: 44px;
  justify-content: center;
  padding: 0;
  position: fixed;
  right: 14px;
  top: 14px;
  width: 44px;
  z-index: 1001;
}

body.preview-open {
  overflow: hidden;
}

.message-audio {
  max-width: 100%;
  width: 280px;
}

.pdf-preview-link {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  max-width: min(360px, 100%);
  overflow: hidden;
}

.pdf-preview {
  border: 0;
  display: block;
  height: 260px;
  pointer-events: none;
  width: 100%;
}

.pdf-preview span {
  align-items: center;
  color: var(--text);
  display: flex;
  font-weight: 700;
  min-height: 120px;
  justify-content: center;
}

.pending-file {
  align-items: center;
  color: var(--text);
  display: flex;
  font-weight: 700;
  min-height: 80px;
  justify-content: center;
  padding: 12px;
}

.attachment-link {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: inline-flex;
  font-weight: 700;
  min-height: 38px;
  padding: 0 12px;
}

.client-panel dl {
  display: grid;
  gap: 8px;
}

.client-panel dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.client-panel dd {
  margin: 0 0 8px;
}

.erp-send {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.erp-send-form {
  display: grid;
  gap: 10px;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.mini-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.erp-send-form label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

code {
  background: #eef2f7;
  border-radius: 6px;
  padding: 2px 5px;
}

@media (max-width: 1100px) {
  .metrics,
  .grid.two-columns,
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    width: auto;
  }

  .content {
    margin-left: 0;
    padding: 20px;
  }

  .chat-page {
    overflow: hidden;
  }

  .chat-page .content {
    height: 100dvh;
    overflow: hidden;
  }

  .chat-layout {
    flex: none;
    height: calc(100dvh - 116px);
    min-height: 0;
    overflow: hidden;
  }

  .conversation-list,
  .client-panel {
    max-height: none;
  }

  .chat-panel {
    min-height: 0;
  }
}

@media (max-width: 760px) {
  .metrics.dashboard-metrics {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
    width: 100%;
  }

  .chat-page .sidebar {
    display: none;
  }

  .chat-page .content {
    height: 100dvh;
    inset: 0;
    margin-left: 0;
    padding: 0;
    width: 100%;
  }

  .chat-page .content > .page-header {
    display: none;
  }

  .chat-page .content > .page-header h1 {
    font-size: 22px;
  }

  .chat-layout,
  .seller-chat-layout {
    display: flex;
    flex-direction: column;
    gap: 0;
    height: 100dvh;
    inset: 0;
    min-height: 0;
    overflow: hidden;
    width: 100%;
  }

  .conversation-list {
    background: var(--surface);
    flex: 1 1 auto;
    height: 100%;
    max-height: none;
    min-height: 0;
    overflow: auto;
    border: 0;
    border-radius: 0;
    padding: 12px;
  }

  .client-panel { display: none; }

  .has-active-chat .conversation-list {
    display: none;
  }

  .chat-list-only .chat-panel {
    display: none;
  }

  .conversation-list .page-header {
    margin-bottom: 10px;
  }

  .conversation-list .page-header h2 {
    font-size: 22px;
  }

  .conversation-item {
    border-bottom: 1px solid #eef2f7;
    padding: 12px 4px;
  }

  .chat-panel {
    background: #eef2f7;
    flex: 1 1 auto;
    border: 0;
    border-radius: 0;
    display: flex;
    gap: 0;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    padding: 0;
    width: 100%;
  }

  .chat-header {
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    flex: 0 0 auto;
    gap: 8px;
    min-height: 54px;
    padding: 8px 10px;
  }

  .back-to-list {
    border: 0;
    border-radius: 999px;
    display: inline-flex;
    flex: 0 0 auto;
    font-size: 28px;
    min-height: 40px;
    min-width: 40px;
    padding: 0;
  }

  .chat-header h2 {
    font-size: 16px;
    margin: 0;
  }

  .handoff-meta {
    display: none;
  }

  .messages-thread {
    background-color: #efeae2;
    background-image: url("../core/chat-wallpaper-light.08fcb6cd628e.svg");
    border: 0;
    border-radius: 0;
    flex: 1 1 auto;
    min-height: 0;
    padding: 10px 8px;
  }

  .bubble {
    max-width: 92%;
  }

  .reply-form {
    align-items: end;
    background: #f0f2f5;
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    flex: 0 0 auto;
    padding: 6px 8px max(6px, env(safe-area-inset-bottom));
    width: 100%;
  }

  .new-messages-button { bottom: 66px; }

  .reply-form > button.primary {
    display: none;
  }

  .composer {
    min-width: 0;
    display: grid;
    gap: 6px;
  }

  .composer-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow: visible;
    padding-bottom: 2px;
  }

  .attach-button {
    flex: 0 0 auto;
    border-radius: 999px;
    font-size: 12px;
    min-height: 28px;
    padding: 0 7px;
  }

  .icon-button {
    height: 40px;
    min-width: 40px;
    width: 40px;
  }

  .reply-form textarea {
    border-radius: 20px;
    font-size: 16px;
    min-height: 42px;
    padding: 9px 10px;
  }

  .attachment-status {
    min-height: 0;
  }

  .reply-form[data-mode="text"] .send-button {
    display: inline-flex;
  }

  .reply-form[data-mode="media"] .send-button {
    display: none;
  }
}

@media (max-width: 760px) and (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --bg: #030608; --surface: #090e11; --line: #202b31; --text: #e9edef; --muted: #8696a0; --primary: #00a884; --primary-dark: #008f72; --accent: #53bdeb; --danger: #f15c6d; --ok: #00a884; }
  input, select, textarea { background: #141d22; border-color: var(--line); color: var(--text); }
  .message, .bubble.entrada { background: #141d22; }
  .message.success { background: #12372f; border-color: #276859; }
  .message.error { background: #3b2023; border-color: #7a373b; }
  .conversation-item { border-bottom-color: var(--line); }
  .conversation-item .conversation-line strong { color: #e9edef; }
  .conversation-item .conversation-preview { color: #8696a0; }
  .conversation-item.active, .conversation-item.unread { background: #141d22; }
  .chat-avatar { background: #202b31; color: #d1d7db; }
  .chat-search input { background: #141d22; }
  .chat-filters button.active { background: #00a884; border-color: #00a884; color: #fff; }
  .chat-panel { background: var(--bg); }
  .messages-thread { background-color: #000; background-image: url("../core/chat-wallpaper-dark.8517bf22f906.svg"); }
  .bubble.saida { background: #005c4b; border-color: #005c4b; }
  .chat-date-separator span { background: #11191d; }
  .reply-form { background: #090e11; }
  .attachment-menu > div, .quick-replies-panel, .message-search { background: #090e11; }
  .chat-filters button,
  .attachment-menu .attach-button,
  .quick-replies-panel button,
  .message-search button { background: #243440; border-color: #425666; color: #edf2f7; }
  .chat-filters button:hover,
  .chat-filters button:focus-visible,
  .attachment-menu .attach-button:hover,
  .attachment-menu .attach-button:focus-visible,
  .quick-replies-panel button:hover,
  .quick-replies-panel button:focus-visible { background: #304553; border-color: #587080; }
  .chat-filters button.active { background: #00a884; border-color: #00a884; color: #fff; }
  .icon-button, .back-to-list { background: transparent; border: 0; color: #d6e1e8; }
  .icon-button:hover, .icon-button:focus-visible, .back-to-list:hover, .back-to-list:focus-visible { background: rgba(169, 181, 194, .16); border: 0; }
  .send-button { background: var(--primary); border: 0; color: #062923; }
  .badge, code { color-scheme: dark; }
  .favorite-chat-menu-card { background: #111b21; }
  .in-app-notification { background: #111b21; border-color: #202b31; color: #e9edef; }
  .in-app-notification strong { color: #e9edef; }
  .notification-preview { color: #8696a0; }
  .notification-avatar { background: #202b31; color: #d1d7db; }
}
