/* Painel das conversas da recuperação (Autoagente): estilo WhatsApp Web, tema claro e escuro. */

:root {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-soft: #f6f8fa;
  --surface-hover: #f0f3f7;
  --surface-active: #e7effd;
  --chat-bg: #efeae2;
  --border: #dde2ea;
  --border-soft: #e9edf2;
  --text: #1c2430;
  --text-strong: #0e1520;
  --muted: #677386;
  --brand: #1f5fd6;
  --brand-strong: #164bb0;
  --brand-wash: rgba(31, 95, 214, 0.09);
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --green: #15803d;
  --green-wash: rgba(21, 128, 61, 0.1);
  --amber: #a16207;
  --amber-wash: rgba(202, 138, 4, 0.13);
  --red: #c2410c;
  --red-strong: #b42318;
  --red-wash: rgba(220, 38, 38, 0.09);
  --shadow: 0 16px 48px rgba(17, 24, 39, 0.12);
  --radius: 14px;
  --scrollbar: #c3cad5;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0b1016;
  --surface: #121922;
  --surface-soft: #0f151d;
  --surface-hover: #18212c;
  --surface-active: #1a2a42;
  --chat-bg: #0c1218;
  --border: #243040;
  --border-soft: #1b2531;
  --text: #e5ebf2;
  --text-strong: #ffffff;
  --muted: #8d9aab;
  --brand: #6ea2ff;
  --brand-strong: #92baff;
  --brand-wash: rgba(110, 162, 255, 0.12);
  --bubble-in: #1b2430;
  --bubble-out: #133a2b;
  --green: #4ade80;
  --green-wash: rgba(74, 222, 128, 0.12);
  --amber: #fbbf24;
  --amber-wash: rgba(251, 191, 36, 0.12);
  --red: #fb923c;
  --red-strong: #f87171;
  --red-wash: rgba(248, 113, 113, 0.12);
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  --scrollbar: #2e3a4a;
}

* {
  box-sizing: border-box;
  scrollbar-color: var(--scrollbar) transparent;
  scrollbar-width: thin;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button,
select {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--text-strong);
}

/* ---------- botões e campos ---------- */

.primary-button {
  min-height: 2.6rem;
  padding: 0 1.15rem;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-weight: 650;
  transition: background 120ms ease, opacity 120ms ease;
}

:root[data-theme='dark'] .primary-button {
  color: #0b1016;
}

.primary-button:hover:not(:disabled) {
  background: var(--brand-strong);
}

.primary-button:disabled {
  opacity: 0.45;
}

.ghost-button,
.theme-toggle {
  min-height: 2.2rem;
  padding: 0 0.85rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.ghost-button:hover:not(:disabled),
.theme-toggle:hover {
  background: var(--surface-hover);
}

.ghost-button:disabled {
  opacity: 0.45;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.theme-icon {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: linear-gradient(90deg, var(--text) 50%, transparent 50%);
  border: 1.5px solid var(--text);
}

.theme-toggle.floating {
  position: fixed;
  top: 1rem;
  right: 1rem;
}

input,
select {
  width: 100%;
  min-height: 2.5rem;
  padding: 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-wash);
}

.form-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--red-strong);
  font-size: 0.85rem;
}

/* ---------- login ---------- */

.login-shell {
  display: grid;
  min-height: 100%;
  padding: 1.5rem;
  place-items: center;
  overflow-y: auto;
  background: radial-gradient(circle at 15% 10%, var(--brand-wash), transparent 28rem), var(--bg);
}

.login-card {
  width: min(100%, 25rem);
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0.3rem 0 0.5rem;
  font-size: 1.45rem;
  line-height: 1.2;
}

.login-copy {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.login-form {
  display: grid;
  gap: 0.9rem;
}

.login-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.brand-mark {
  display: grid;
  width: 3rem;
  height: 3rem;
  margin-bottom: 1rem;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), #16a34a);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-mark.small {
  width: 2.3rem;
  height: 2.3rem;
  margin: 0;
  border-radius: 11px;
  font-size: 0.85rem;
}

/* ---------- estrutura ---------- */

.dashboard {
  display: flex;
  height: 100%;
  flex-direction: column;
}

.topbar {
  display: flex;
  min-height: 3.9rem;
  align-items: center;
  gap: 1.5rem;
  padding: 0.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand-inline {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand-inline h1 {
  font-size: 1rem;
}

.primary-nav {
  display: flex;
  gap: 0.3rem;
  margin-right: auto;
}

.nav-button {
  min-height: 2.3rem;
  padding: 0 0.95rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}

.nav-button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-button.active {
  background: var(--brand-wash);
  color: var(--brand);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.workspace {
  display: grid;
  min-height: 0;
  flex: 1;
  grid-template-columns: clamp(19rem, 27vw, 25rem) minmax(0, 1fr);
}

/* ---------- lista de leads ---------- */

.lead-pane {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.pane-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.6rem;
}

.pane-heading h2 {
  font-size: 1.15rem;
}

.count-badge {
  min-width: 2rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--brand-wash);
  color: var(--brand);
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

.lead-search {
  display: grid;
  gap: 0.5rem;
  padding: 0 1rem 0.75rem;
  border-bottom: 1px solid var(--border-soft);
}

.lead-search select {
  min-height: 2.2rem;
  font-size: 0.85rem;
}

.lead-list {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
}

.lead-item {
  display: flex;
  width: 100%;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 0;
  border-bottom: 1px solid var(--border-soft);
  background: transparent;
  text-align: left;
}

.lead-item:hover {
  background: var(--surface-hover);
}

.lead-item.active {
  background: var(--surface-active);
}

.lead-main {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 0.2rem;
}

.lead-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.lead-name {
  overflow: hidden;
  color: var(--text-strong);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-time {
  flex: none;
  color: var(--muted);
  font-size: 0.75rem;
}

.lead-preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.84rem;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  word-break: break-word;
}

.preview-author {
  color: var(--text);
  font-weight: 600;
}

.lead-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.15rem;
}

.empty-list,
.timeline-empty {
  padding: 2rem 1rem;
  color: var(--muted);
  text-align: center;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---------- etiquetas e avatar ---------- */

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 1.3rem;
  padding: 0 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 650;
  white-space: nowrap;
}

.tag-neutral {
  background: var(--brand-wash);
  color: var(--brand);
}

.tag-success,
.tag-open {
  background: var(--green-wash);
  color: var(--green);
}

.tag-open::before {
  width: 0.4rem;
  height: 0.4rem;
  margin-right: 0.3rem;
  border-radius: 50%;
  background: currentColor;
  content: '';
}

.tag-warning {
  background: var(--amber-wash);
  color: var(--amber);
}

.tag-danger {
  background: var(--red-wash);
  color: var(--red-strong);
}

.tag-muted {
  background: var(--surface-hover);
  color: var(--muted);
}

.avatar {
  display: grid;
  width: 2.6rem;
  height: 2.6rem;
  flex: none;
  place-items: center;
  border-radius: 50%;
  background: #5b7cfa;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
}

.avatar.large {
  width: 2.5rem;
  height: 2.5rem;
}

.avatar[data-tone='1'] { background: #0f9d76; }
.avatar[data-tone='2'] { background: #d9822b; }
.avatar[data-tone='3'] { background: #9b5de5; }
.avatar[data-tone='4'] { background: #e05666; }
.avatar[data-tone='5'] { background: #2a9bc4; }

/* ---------- conversa ---------- */

.conversation-pane {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: var(--chat-bg);
}

.conversation-empty {
  display: grid;
  height: 100%;
  padding: 2rem;
  place-content: center;
  justify-items: center;
  gap: 0.6rem;
  color: var(--muted);
  text-align: center;
}

.conversation-empty h2 {
  font-size: 1.2rem;
}

.conversation-empty p {
  max-width: 24rem;
  margin: 0;
}

.empty-orbit {
  display: grid;
  width: 5rem;
  height: 5rem;
  margin-bottom: 0.5rem;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: 50%;
}

.empty-orbit span {
  display: grid;
  width: 3rem;
  height: 3rem;
  place-items: center;
  border-radius: 50%;
  background: var(--brand-wash);
  color: var(--brand);
  font-weight: 800;
}

.conversation-content {
  display: flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}

.conversation-header {
  display: flex;
  min-height: 4rem;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.mobile-back {
  display: none;
  width: 2.2rem;
  height: 2.2rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.2rem;
}

.conversation-identity {
  min-width: 0;
}

.conversation-identity h2 {
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-identity p {
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.message-timeline {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 0.45rem;
  padding: 1rem clamp(0.75rem, 4vw, 3.5rem) 1.25rem;
  overflow-y: auto;
}

.older-button {
  align-self: center;
  margin-bottom: 0.5rem;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.8rem;
}

.day-separator {
  align-self: center;
  margin: 0.6rem 0 0.3rem;
  padding: 0.2rem 0.75rem;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.message {
  max-width: min(78%, 38rem);
  padding: 0.5rem 0.7rem 0.4rem;
  border-radius: 12px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

.message.inbound {
  align-self: flex-start;
  border-top-left-radius: 4px;
  background: var(--bubble-in);
}

.message.outbound {
  align-self: flex-end;
  border-top-right-radius: 4px;
  background: var(--bubble-out);
}

.message-label {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.15rem 0.75rem;
  margin-bottom: 0.15rem;
  font-size: 0.72rem;
}

.message-author {
  color: var(--brand);
  font-weight: 700;
}

.message.inbound .message-author {
  color: #0f9d76;
}

:root[data-theme='dark'] .message.inbound .message-author {
  color: #34d399;
}

.message-type {
  color: var(--muted);
}

.message-content {
  margin: 0;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-content a {
  color: var(--brand);
  word-break: break-all;
}

.message-audio {
  display: block;
  width: min(100%, 20rem);
  height: 2.4rem;
  margin: 0.15rem 0 0.3rem;
}

.audio-transcript {
  margin: 0.2rem 0 0.1rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.message-missing {
  margin: 0.15rem 0 0.3rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-style: italic;
}

.purchase-event {
  display: grid;
  align-self: center;
  gap: 0.1rem;
  margin: 0.4rem 0;
  padding: 0.5rem 1rem;
  border: 1px solid color-mix(in srgb, var(--green) 40%, var(--border));
  border-radius: 12px;
  background: var(--surface);
  color: var(--green);
  text-align: center;
}

.purchase-event strong {
  font-size: 0.9rem;
}

.purchase-event small {
  color: var(--muted);
  font-size: 0.75rem;
}

.read-only-note {
  margin: 0;
  padding: 0.55rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.message-meta {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.7rem;
}

/* ---------- visão geral ---------- */

.overview-view {
  min-height: 0;
  flex: 1;
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 2.5rem;
  overflow-y: auto;
}

.view-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  margin-bottom: 1.25rem;
}

.period-field select {
  min-width: 13rem;
}

.view-heading h2 {
  font-size: 1.5rem;
}

.view-heading p:not(.eyebrow) {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.9rem;
}

.summary-card {
  display: grid;
  gap: 0.25rem;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.summary-card span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.summary-card strong {
  color: var(--text-strong);
  font-size: 1.9rem;
  line-height: 1.1;
}

.summary-card small {
  color: var(--muted);
  font-size: 0.78rem;
}

.summary-card.accent {
  border-color: color-mix(in srgb, var(--green) 40%, var(--border));
  background: linear-gradient(160deg, var(--green-wash), var(--surface) 70%);
}

.summary-note {
  margin: 1.1rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

/* ---------- toast e carregamento ---------- */

.toast {
  position: fixed;
  z-index: 20;
  bottom: 1.25rem;
  left: 50%;
  max-width: min(calc(100% - 2rem), 32rem);
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: var(--text-strong);
  box-shadow: var(--shadow);
  color: var(--surface);
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0.5rem);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.skeleton {
  height: 4.3rem;
  margin: 0.5rem 1rem;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--surface-hover), var(--surface-soft), var(--surface-hover));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.skeleton.tall {
  width: min(60%, 26rem);
  height: 3.5rem;
  margin: 0.2rem 0;
}

.skeleton.tall.right {
  align-self: flex-end;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
}

/* ---------- telas menores ---------- */

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    padding: 0.5rem 0.75rem;
  }

  .primary-nav {
    order: 3;
    width: 100%;
    margin: 0;
  }

  .primary-nav .nav-button {
    flex: 1;
  }

  .topbar-actions {
    margin-left: auto;
  }

  .theme-toggle [data-theme-label] {
    display: none;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .conversation-pane {
    display: none;
  }

  .workspace.conversation-open .lead-pane {
    display: none;
  }

  .workspace.conversation-open .conversation-pane {
    display: flex;
  }

  .mobile-back {
    display: grid;
    place-items: center;
  }

  .conversation-header {
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
  }

  .conversation-identity {
    flex: 1;
  }

  .conversation-badges {
    order: 4;
    width: 100%;
  }

  .message {
    max-width: 88%;
  }

  .period-field,
  .period-field select {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .brand-inline .eyebrow,
  #refresh-button {
    display: none;
  }
}
