/* ==========================================================================
   FozContabil — Design System
   Tema padrão: "tech claro" (cinza/grafite). Tema escuro opcional via
   [data-theme="dark"] no <html>. Todos os valores são tokens CSS.
   ========================================================================== */

:root {
  /* --- Superfícies --- */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f1f3f5;
  --overlay: rgba(15, 18, 22, 0.45);

  /* --- Texto --- */
  --text: #12151a;
  --text-secondary: #5b6472;
  --text-muted: #8b93a1;
  --text-inverse: #ffffff;

  /* --- Bordas --- */
  --border: #e4e7ec;
  --border-strong: #d0d5dd;

  /* --- Accent (grafite) --- */
  --accent: #2b3038;
  --accent-hover: #1a1e24;
  --accent-soft: #eef0f3;
  --accent-contrast: #ffffff;

  /* --- Semânticas (discretas, para acessibilidade) --- */
  --success: #1a7f4b;
  --success-soft: #e7f5ee;
  --danger: #c0392b;
  --danger-soft: #fbeceb;
  --warning: #a16207;
  --warning-soft: #fdf3e0;
  --info: #2563eb;
  --info-soft: #e8f0fe;

  /* --- Foco / sombra --- */
  --focus: #6b7280;
  --shadow-sm: 0 1px 2px rgba(16, 18, 22, 0.05);
  --shadow: 0 4px 16px rgba(16, 18, 22, 0.08);
  --shadow-lg: 0 18px 48px rgba(16, 18, 22, 0.16);

  /* --- Raio --- */
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --r-full: 9999px;

  /* --- Espaço / tipografia --- */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-w: 250px;
  --sidebar-w-collapsed: 68px;
  --topbar-h: 58px;

  /* --- Login / páginas públicas --- */
  --brand-grad-1: #2563eb;
  --brand-grad-2: #7c3aed;
  --brand-grad-glow: rgba(79, 70, 229, 0.45);
  --auth-card-bg: rgba(255, 255, 255, 0.78);
  --auth-card-border: var(--border-strong);
  --auth-card-highlight: rgba(255, 255, 255, 0.9);
  --auth-inner-border: var(--border);
  --auth-foot-bg: var(--surface-2);
  --auth-bottom: #eef1f6;
  --auth-glow-1: rgba(37, 99, 235, 0.16);
  --auth-glow-2: rgba(124, 58, 237, 0.12);
  --auth-halo-1: rgba(37, 99, 235, 0.1);
  --auth-halo-2: rgba(124, 58, 237, 0.1);
}

[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #161a20;
  --surface-2: #1b2027;
  --surface-3: #232932;
  --overlay: rgba(0, 0, 0, 0.6);

  --text: #e8eaed;
  --text-secondary: #a3abb8;
  --text-muted: #6f7884;
  --text-inverse: #12151a;

  --border: #262c35;
  --border-strong: #35404d;

  --accent: #e8eaed;
  --accent-hover: #ffffff;
  --accent-soft: #232932;
  --accent-contrast: #12151a;

  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --info: #60a5fa;
  --info-soft: rgba(96, 165, 250, 0.12);

  --focus: #6b7280;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.6);

  /* --- Login / páginas públicas --- */
  --brand-grad-glow: rgba(79, 70, 229, 0.55);
  --auth-card-bg: rgba(22, 26, 32, 0.72);
  --auth-card-border: rgba(255, 255, 255, 0.08);
  --auth-card-highlight: rgba(255, 255, 255, 0.06);
  --auth-inner-border: rgba(255, 255, 255, 0.07);
  --auth-foot-bg: rgba(0, 0, 0, 0.2);
  --auth-bottom: #0a0c10;
  --auth-glow-1: rgba(79, 70, 229, 0.22);
  --auth-glow-2: rgba(124, 58, 237, 0.18);
  --auth-halo-1: rgba(37, 99, 235, 0.12);
  --auth-halo-2: rgba(124, 58, 237, 0.12);
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}
h1 {
  font-size: 1.4rem;
}
h2 {
  font-size: 1.05rem;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Ícone do botão de tema: mostra a lua no claro e o sol no escuro */
.only-dark {
  display: none;
}
[data-theme="dark"] .only-light {
  display: none;
}
[data-theme="dark"] .only-dark {
  display: inline-flex;
}

.link-sutil {
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.link-sutil:hover {
  color: var(--text);
}

.card-foot {
  margin-top: 1.5rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  text-align: center;
}
.card-foot .version {
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.75;
}

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

.muted {
  color: var(--text-secondary);
}
.text-muted {
  color: var(--text-muted);
}

/* ==========================================================================
   App shell
   ========================================================================== */

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
  transition: width 0.18s ease, transform 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  height: var(--topbar-h);
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--brand-grad-1), var(--brand-grad-2));
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
}
/* Logo da empresa no topo do painel (substitui o selo quando há logo). */
.brand-logo {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--surface);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem 0.6rem 1rem;
}

.nav-section {
  margin: 0.9rem 0 0.3rem;
  padding: 0 0.6rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.6rem;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover {
  background: var(--surface-3);
  color: var(--text);
  text-decoration: none;
}
.nav-item.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}
[data-theme="dark"] .nav-item.active {
  background: var(--surface-3);
}
.nav-item .icon {
  flex: 0 0 18px;
  display: grid;
  place-items: center;
  color: currentColor;
}
.nav-item .badge {
  margin-left: auto;
}

.sidebar-foot {
  padding: 0.5rem;
  border-top: 1px solid var(--border);
}
.collapse-btn {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.45rem 0.5rem;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}
.collapse-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}
.collapse-btn .icon {
  flex: 0 0 18px;
  transition: transform 0.18s ease;
}
.shell.collapsed .collapse-btn {
  justify-content: center;
}
.shell.collapsed .collapse-btn .icon {
  transform: rotate(180deg);
}
.shell.collapsed .collapse-btn .txt {
  display: none;
}

.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.18s ease;
}
/* Tela de conversas (app de chat): a janela inteira é viewport do app —
   nada de rolagem de página; rolar é trabalho da lista e das mensagens. */
.main:has(.conversas) {
  height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--topbar-h);
  padding: 0 1.25rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-size: 1rem;
  font-weight: 650;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.icon-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  height: 36px;
  padding: 0 0.7rem 0 0.25rem;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
}
.user-chip .avatar {
  width: 28px;
  height: 28px;
  flex-basis: 28px;
  font-size: 0.72rem;
}
.user-chip .ident {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.user-chip .name {
  font-size: 0.82rem;
  font-weight: 600;
}
.user-chip .role {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.content {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 2.5rem;
}
/* Tela de conversas: usa 100% do espaço disponível (sem teto de largura) —
   a janela não rola; rolar é trabalho da lista e das mensagens. */
.content:has(.conversas) {
  display: flex;
  flex-direction: column;
  max-width: none;
  min-height: 0;
  padding-bottom: 1rem;
}
.content:has(.conversas) .conversas {
  flex: 1;
  min-height: 420px;
  height: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-head .sub {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.2rem;
}
.page-actions {
  display: flex;
  gap: 0.5rem;
}

/* Collapsed sidebar (desktop) */
.shell.collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
}
.shell.collapsed .sidebar .label,
.shell.collapsed .sidebar-brand .name,
.shell.collapsed .nav-section {
  display: none;
}
.shell.collapsed .main {
  margin-left: var(--sidebar-w-collapsed);
}
.shell.collapsed .nav-item {
  justify-content: center;
  padding: 0.55rem;
}

/* Mobile */
.sidebar-backdrop {
  display: none;
}
@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
  }
  .shell.nav-open .sidebar {
    transform: translateX(0);
  }
  .shell .main,
  .shell.collapsed .main {
    margin-left: 0;
  }
  .shell.nav-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 35;
  }
  .topbar .menu-toggle {
    display: grid;
  }
  .desktop-only {
    display: none !important;
  }

  /* Conversas no celular: lista e conversa em pilha; abrir conversa mostra
     só ela (tela cheia) com botão de voltar. */
  .conversas {
    grid-template-columns: 1fr;
    height: calc(100dvh - var(--topbar-h) - 2rem);
  }
  .conversas.mostrou-thread .conversas-lista {
    display: none;
  }
  /* Sem conversa aberta no celular: só a lista (o vazio não passa de respiro) */
  .conversas:not(.mostrou-thread) .thread {
    display: none;
  }
}
@media (min-width: 861px) {
  .topbar .menu-toggle {
    display: none;
  }
}

/* ==========================================================================
   Componentes
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.card-head h2 {
  font-size: 0.98rem;
}
.card-body {
  padding: 1.1rem;
}
.card-body.flush {
  padding: 0;
}

/* Canais de WhatsApp (D032): grade de cartões, um por número. */
.canais-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  align-items: start;
}
.canal-card .card-head h2 {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.canal-acoes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
}
.canal-novo .card-body {
  display: flex;
  flex-direction: column;
}
.canal-novo .btn-marca {
  align-self: flex-start;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover {
  background: var(--surface-3);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  filter: brightness(0.94);
}
.btn-sm {
  padding: 0.32rem 0.6rem;
  font-size: 0.8rem;
}
.btn-icon {
  padding: 0.4rem;
  width: 34px;
  height: 34px;
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn-icon:hover {
  background: var(--surface-3);
  color: var(--text);
}
.btn-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

label.field {
  display: block;
  margin-bottom: 0.85rem;
}
label.field > span {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
  font-weight: 550;
  color: var(--text-secondary);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}
.textarea {
  resize: vertical;
  min-height: 74px;
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0 1rem;
}
.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.16rem 0.55rem;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-secondary);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.6;
}
.badge-success {
  background: var(--success-soft);
  color: var(--success);
}
.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}
.badge-info {
  background: var(--info-soft);
  color: var(--info);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--text-muted);
  flex: 0 0 8px;
}
.dot-online {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 650;
  text-transform: uppercase;
}
.avatar-lg {
  width: 44px;
  height: 44px;
  flex-basis: 44px;
  font-size: 0.95rem;
}

.alert {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.7rem 0.9rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.88rem;
}
.alert-error {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--danger);
}
.alert-success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  color: var(--success);
}
.alert-warning {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 30%, transparent);
  color: var(--warning);
}

.empty {
  display: grid;
  place-items: center;
  gap: 0.4rem;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
}
.empty .icon {
  color: var(--text-muted);
  opacity: 0.7;
}
.empty strong {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Tabelas */
.table-wrap {
  overflow-x: auto;
}
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
table.table th {
  text-align: left;
  padding: 0.6rem 1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}
table.table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.table tbody tr:last-child td {
  border-bottom: 0;
}
table.table tbody tr:hover {
  background: var(--surface-2);
}
.table-footer {
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}
.stat {
  padding: 1rem 1.1rem;
}
.stat .label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 550;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat .value {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 0.2rem;
}
.stat .foot {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

/* Modal (via <dialog>) */
dialog.modal {
  width: min(560px, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(2px);
}
dialog.modal .modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
dialog.modal .modal-body {
  padding: 1.1rem;
}
dialog.modal .modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* Visualizador de mídia (dialog grande na mesma tela) */
dialog.vista {
  width: min(920px, calc(100vw - 2rem));
  height: min(88vh, calc(100dvh - 4rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
/* O layout flex só vale com o diálogo aberto; fechado, a regra do navegador
   volta a escondê-lo (sem isso o visualizador ficava fixo na tela). */
dialog.vista[open] {
  display: flex;
  flex-direction: column;
}
dialog.vista::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(3px);
}
dialog.vista .vista-topo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
}
dialog.vista .vista-nome {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
dialog.vista .vista-acoes {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
}
dialog.vista .vista-btn {
  border-radius: var(--r-full);
  padding: 0.42rem 0.85rem;
  transition: background 0.14s ease, box-shadow 0.14s ease, color 0.14s ease,
    filter 0.14s ease, transform 0.14s ease;
}
dialog.vista .vista-btn.btn-ghost {
  background: var(--surface-2);
}
dialog.vista .vista-btn.btn-ghost:hover {
  background: var(--surface-3);
  color: var(--text);
}
dialog.vista .vista-btn.btn-marca:hover {
  transform: translateY(-1px);
}
dialog.vista .vista-fechar {
  width: 34px;
  height: 34px;
  border-radius: var(--r-full);
  color: var(--text-muted);
  transition: background 0.14s ease, color 0.14s ease, transform 0.14s ease;
}
dialog.vista .vista-fechar:hover {
  background: var(--danger-soft);
  color: var(--danger);
  transform: rotate(90deg);
}
dialog.vista .vista-corpo {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0.8rem;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  overflow: hidden;
}
dialog.vista .vista-img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--r);
  object-fit: contain;
}
dialog.vista .vista-video {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--r);
}
dialog.vista .vista-audio {
  width: min(420px, 100%);
}
dialog.vista .vista-embed {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: var(--r);
  background: #fff;
}
/* Navegador sem viewer de PDF: aviso central com ações */
.vista-fallback {
  text-align: center;
  color: var(--text-secondary);
  display: grid;
  gap: 0.7rem;
  justify-items: center;
}
.vista-fallback .vista-fallback-acoes {
  display: flex;
  gap: 0.5rem;
}
dialog.vista .vista-pe {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
dialog.vista .vista-legenda {
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
dialog.vista .vista-legenda::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 1em;
  margin-right: 0.55rem;
  vertical-align: -0.16em;
  border-radius: var(--r-full);
  background: linear-gradient(180deg, var(--brand-grad-1), var(--brand-grad-2));
}
/* Imagem da bolha agora vive dentro de um botão (abre o visualizador) */
.msg-img-btn {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  max-width: 100%;
}
.msg-img-btn .msg-img {
  cursor: zoom-in;
}
/* Card de documento também é botão agora */
button.msg-doc {
  font: inherit;
  text-align: left;
}
/* Impressão: quando o navegador imprime o iframe, a página pai não aparece */
@media print {
  body * {
    visibility: hidden;
  }
  #vista-print-frame,
  #vista-print-frame * {
    visibility: visible;
  }
  #vista-print-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }
}

/* Toast */
.toast-stack {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  animation: toast-in 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast-success {
  border-left: 3px solid var(--success);
}
.toast-error {
  border-left: 3px solid var(--danger);
}
.toast-info {
  border-left: 3px solid var(--info);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Skeleton */
.skeleton {
}
/* Pontinho pulsante do "aguardando a leitura do QR" */
.skeleton-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 0.3rem;
  border-radius: var(--r-full);
  background: var(--info);
  animation: pulso 1.2s ease-in-out infinite;
}
@keyframes pulso {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
  border-radius: var(--r-sm);
  background: linear-gradient(
    90deg,
    var(--surface-3) 25%,
    var(--surface-2) 37%,
    var(--surface-3) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* Login / páginas públicas */
body.auth-body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}
.auth-wrap {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: 28px 16px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 90% 70% at 50% -10%, var(--auth-glow-1), transparent 60%),
    radial-gradient(ellipse 70% 60% at 100% 110%, var(--auth-glow-2), transparent 55%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg) 45%, var(--auth-bottom) 100%);
}
/* Halo suave que dá profundidade ao fundo (como o degradê do gratitude). */
.auth-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(50% 40% at 18% 18%, var(--auth-halo-1), transparent 70%),
    radial-gradient(45% 40% at 85% 80%, var(--auth-halo-2), transparent 70%);
  filter: blur(6px);
}
.auth-col {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 448px;
}
.auth-card {
  position: relative;
  width: 100%;
  padding: 28px;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid var(--auth-card-border);
  background: var(--auth-card-bg);
  box-shadow: var(--shadow-lg), inset 0 1px 0 var(--auth-card-highlight);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0;
  margin-bottom: 24px;
}
/* Área da marca: mesma altura da logo do gratitude (min(196px, 32vh)),
   para o card ter exatamente a mesma altura, com logo vertical ou selo. */
.auth-media {
  display: grid;
  place-items: center;
  height: min(196px, 32vh);
}
/* Logo configurada (APP_LOGO_URL) ou selo com a inicial do app. */
.auth-logo {
  width: auto;
  max-width: min(8.5rem, 70vw);
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
}
.auth-seal {
  display: grid;
  place-items: center;
  width: var(--brand-size, 84px);
  height: var(--brand-size, 84px);
  border-radius: 22px;
  font-size: calc(var(--brand-size, 84px) * 0.42);
  font-weight: 700;
  color: #fff;
  background: linear-gradient(140deg, var(--brand-grad-1), var(--brand-grad-2));
  box-shadow:
    0 10px 26px -8px var(--brand-grad-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
/* Filete degradê que separa a marca do título (igual ao gratitude). */
.auth-rule {
  width: 96px;
  height: 2px;
  margin: 12px 0 0;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--brand-grad-1), var(--brand-grad-2));
  opacity: 0.9;
}
.auth-empresa {
  margin: 12px 0 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  text-align: center;
}
/* Campo com botão de ação embutido (ex.: CNPJ + Buscar) */
.input-acao {
  display: flex;
  gap: 0.5rem;
}
.input-acao .input {
  flex: 1;
  min-width: 0;
}
.input-acao .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
/* Escolha de cor: amostra + valor + limpar */
.cor-escolha {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.cor-picker {
  flex: 0 0 auto;
  width: 44px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
}
/* Título de seção dentro de um formulário (ex.: Endereço) */
.form-secao {
  margin: 1.1rem 0 0.3rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
/* Ações do formulário (Salvar + Cancelar) */
.form-acoes {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
}

/* Minha empresa: um card só, logo à esquerda e dados em 2 colunas */
.empresa-grid {
  display: grid;
  grid-template-columns: 208px 1fr;
  gap: 1.4rem;
  align-items: start;
}
.empresa-logo {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.logo-preview {
  display: grid;
  place-items: center;
  min-height: 150px;
  padding: 0.6rem;
  border: 1px dashed var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
}
.logo-preview img {
  max-width: 100%;
  max-height: 150px;
  border-radius: var(--r-sm);
}
.empresa-dados .form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (max-width: 720px) {
  .empresa-grid {
    grid-template-columns: 1fr;
  }
  .empresa-dados .form-grid {
    grid-template-columns: 1fr;
  }
}
.auth-title {
  margin-top: 16px;
  font-size: 20px;
  font-weight: 700;
  line-height: 28px;
  letter-spacing: -0.02em;
}
.auth-tagline {
  margin: 4px 0 0;
  max-width: 100%;
  font-size: 14px;
  line-height: 20px;
  color: var(--text-secondary);
}
.auth-body-inner {
  padding: 0;
}
.auth-alert {
  margin-bottom: 14px;
}
.auth-sub {
  font-size: 1.05rem;
}

/* Formulário das páginas públicas nas medidas do gratitude */
.auth-body form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-body label.field {
  margin: 0;
}
.auth-body label.field > span {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
  color: var(--text);
}
.auth-body .input {
  padding: 8px 12px;
  font-size: 14px;
  line-height: 20px;
  border-radius: 8px;
}

/* Campos com ícone e botão de mostrar senha (medidas do gratitude) */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin-top: 4px;
}
.input-wrap .input {
  padding-left: 40px;
}
.input-wrap .input:has(+ .input-eye),
.input-wrap .input[type="password"] {
  padding-right: 40px;
}
.input-icon {
  position: absolute;
  left: 12px;
  display: inline-flex;
  color: var(--text-muted);
  pointer-events: none;
}
.input-icon .icon {
  width: 16px;
  height: 16px;
}
.input-eye {
  position: absolute;
  right: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.input-eye:hover {
  color: var(--text);
  background: var(--surface-3);
}
.input-eye .only-visivel,
.input-wrap.revelado .only-oculto {
  display: none;
}
.input-wrap.revelado .only-visivel {
  display: inline-flex;
}

/* Botão principal com degradê (altura 40px, igual ao gratitude) */
.btn-primary {
  border: 0;
  background: linear-gradient(120deg, var(--brand-grad-1), var(--brand-grad-2));
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 24px -10px var(--brand-grad-glow);
}
.btn-primary:hover {
  filter: brightness(1.06);
  background: linear-gradient(120deg, var(--brand-grad-1), var(--brand-grad-2));
}
/* Botão de ação da marca (degradê azul→roxo), para CTAs pontuais fora do login */
.btn-marca {
  border: 0;
  background: linear-gradient(120deg, var(--brand-grad-1), var(--brand-grad-2));
  color: #fff;
  font-weight: 600;
  box-shadow: 0 8px 20px -10px var(--brand-grad-glow);
}
.btn-marca:hover {
  filter: brightness(1.08);
  background: linear-gradient(120deg, var(--brand-grad-1), var(--brand-grad-2));
  box-shadow: 0 10px 24px -10px var(--brand-grad-glow);
}
.btn-block {
  width: 100%;
  margin-top: 2px;
  padding: 10px 16px;
  font-size: 14px;
  line-height: 20px;
  border-radius: 8px;
}
.btn .btn-loading {
  display: none;
}
.btn.carregando .btn-label {
  display: none;
}
.btn.carregando .btn-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.spin {
  animation: foz-spin 0.7s linear infinite;
}
@keyframes foz-spin {
  to {
    transform: rotate(360deg);
  }
}
.auth-links {
  margin-top: 8px;
  line-height: 24px;
  text-align: center;
}
.auth-links .link-sutil {
  font-size: 14px;
  font-weight: 500;
}
/* "← Voltar ao login" (azul, como no gratitude) */
.link-voltar {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  color: var(--info);
}
.link-voltar:hover {
  text-decoration: underline;
  filter: brightness(1.12);
}
.link-voltar .icon {
  width: 16px;
  height: 16px;
}
.auth-links-voltar {
  margin-top: 16px;
}

.auth-card .card-foot {
  margin-top: 20px;
  padding: 16px 0 0;
  background: transparent;
  border-top: 0;
  text-align: center;
}
.auth-card .card-foot .copyright {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
  color: var(--text-secondary);
}
.auth-card .card-foot .version {
  margin: 4px 0 0;
  font-size: 12px;
  font-weight: 400;
  line-height: 16px;
  color: var(--text-muted);
  opacity: 0.85;
}
.auth-byline {
  position: relative;
  margin: 16px 0 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 16px;
}
.auth-byline a {
  color: var(--text-secondary);
  font-weight: 500;
}

/* Em telas baixas, enxuga o espaçamento para caber sem rolagem */
@media (max-height: 720px) {
  .auth-brand {
    margin-bottom: 18px;
  }
  .auth-media {
    height: min(120px, 20vh);
  }
  body.auth-body {
    overflow: auto;
  }
}

/* Conversas */
.conversas {
  display: grid;
  /* Colunas proporcionais à tela (não fixas): lista ~28% com limites de
     conforto (260px–360px) e conversa tomando o resto. */
  grid-template-columns: clamp(260px, 28%, 360px) 1fr;
  gap: 1rem;
  /* App de chat: ocupa da borda superior até o fim da janela — a altura exata
     vem do .content (flex), sem conta manual que sobra faixa embaixo. */
  min-height: 420px;
  align-items: stretch;
}
@media (max-width: 860px) {
  .conversas {
    grid-template-columns: 1fr;
  }
}
.conversas-lista {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search .icon {
  position: absolute;
  left: 0.6rem;
  color: var(--text-muted);
  pointer-events: none;
}
.search .input {
  padding-left: 2rem;
}
.filtros {
  display: flex;
  gap: 0.35rem;
  padding: 0.6rem 0.85rem 0.7rem;
  flex-wrap: wrap;
}
.conversas-resultado {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.chip {
  padding: 0.28rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 550;
  cursor: pointer;
}
.chip:hover {
  background: var(--surface-3);
}
.chip-active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* Barra de rolagem invisível (rolagem continua funcionando) */
  scrollbar-width: none;
}
.conv-list::-webkit-scrollbar {
  display: none;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.85rem;
  border-top: 1px solid var(--border);
  color: var(--text);
}
.conv-item:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.conv-item.active {
  background: var(--surface-3);
}
.conv-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.conv-name {
  font-weight: 550;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-phone {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.conv-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
}
.conv-time {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.thread {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.thread-topo {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.btn-nome {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-left: 0.35rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  vertical-align: middle;
  cursor: pointer;
}
.btn-nome:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border);
}
/* Ações do cabeçalho: assumir/soltar/reatribuir/fechar */
.thread-acoes {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
/* Responsável identificado na lista (iniciais) */
.conv-assumida {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: var(--r-full);
  background: var(--info-soft);
  color: var(--info);
  font-size: 0.62rem;
  font-weight: 700;
}
.conv-item.minha .conv-name {
  color: var(--info);
}
/* Ponto de "não lida" na lista */
.nao-lida-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 0.35rem;
  border-radius: var(--r-full);
  background: var(--brand-grad-1);
}
/* Faixa de conversa fechada (no pé da thread, no lugar do compositor) */
.fechada-aviso {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 0.88rem;
}
.fechada-aviso .icon {
  color: var(--success);
  flex: 0 0 auto;
}
.fechada-aviso form {
  margin: 0;
}
/* Voltar à lista (aparece só no celular; mobile mostra com !important) */
.btn-voltar-lista {
  display: none !important;
}
@media (max-width: 860px) {
  .btn-voltar-lista {
    display: inline-flex !important;
  }
  /* Cabeçalho estreito: nome/status na 1ª linha; ações assumem a 2ª linha,
     em vez de espremer o nome em uma coluna de uma palavra por linha. */
  .thread-topo {
    flex-wrap: wrap;
    row-gap: 0.5rem;
  }
  .thread-acoes {
    width: 100%;
    justify-content: flex-start;
  }
}
/* Aviso "mensagens novas" quando o usuário está lendo o histórico */
.aviso-novas {
  position: absolute;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.aviso-novas:hover {
  background: var(--accent-soft);
}
.conversas-vazio-empty {
  flex: 1;
}
.mensagens {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem 1.1rem;
  overflow-y: auto;
  min-height: 0;
  /* Barra de rolagem invisível (rolagem continua funcionando) */
  scrollbar-width: none;
}
.mensagens::-webkit-scrollbar {
  display: none;
}
.msg {
  display: flex;
  flex-direction: column;
  max-width: 76%;
}
.msg .bolha {
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.9rem;
}
.msg .meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
/* Meta dentro da bolha enviada (autoria+hora viajam com a mensagem) */
.msg.enviada .bolha .meta {
  margin-top: 0.3rem;
  margin-bottom: -0.15rem;
  color: rgba(255, 255, 255, 0.75);
}
.msg.recebida {
  align-self: flex-start;
}
.msg.recebida .meta {
  margin-left: 0.35rem;
}
.msg.recebida .bolha {
  background: var(--surface-3);
}
.msg.enviada {
  align-self: flex-end;
  align-items: flex-end;
}
/* Enviada: gradiente da marca (igual ao selo das páginas públicas) + texto claro. */
.msg.enviada .bolha {
  background: linear-gradient(140deg, var(--brand-grad-1), var(--brand-grad-2));
  color: #fff;
}
.msg.enviada .meta {
  color: var(--text-muted);
}
/* Status de entrega na bolha enviada (D024): ✓ / ✓✓ / azul quando lida. */
.msg-status {
  margin-left: 0.3rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.msg.enviada .bolha .msg-status {
  color: rgba(255, 255, 255, 0.8);
}
.msg.enviada .bolha .msg-status-read,
.msg.enviada .bolha .msg-status-played {
  color: #7dd3fc; /* azul-claro, contraste sobre o gradiente */
}
.msg-status-read,
.msg-status-played {
  color: var(--info);
}
.msg-editada {
  margin-left: 0.4rem;
  font-size: 0.68rem;
  font-style: italic;
  opacity: 0.8;
}
/* Mensagem de mídia (áudio/imagem/vídeo/documento): sem balão — o próprio
   anexo é o conteúdo. Legenda/citação, quando houver, fica solta abaixo. */
.msg.midia .bolha {
  padding: 0;
  background: transparent;
  border-radius: 0;
}
/* Legenda de mídia: pílula que abraça só o texto (não estica até a largura da
   imagem/balão). Texto longo quebra dentro de `max-width: 100%`. */
.msg.midia .bolha .legenda {
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  margin-top: 0.35rem;
  padding: 0.4rem 0.6rem;
  border-radius: 12px;
  background: var(--surface-3);
  font-size: 0.9rem;
}
.msg.midia.enviada .bolha .legenda {
  background: linear-gradient(140deg, var(--brand-grad-1), var(--brand-grad-2));
  color: #fff;
}
/* Citação numa bolha de mídia ainda precisa do próprio fundo. */
.msg.midia .bolha .msg-citacao {
  margin-bottom: 0.35rem;
  padding: 0.35rem 0.6rem;
  background: var(--surface-3);
}
.msg.midia.enviada .bolha .msg-citacao {
  background: rgba(255, 255, 255, 0.16);
}

/* Mensagem apagada: texto esmaecido, sem fingir conteúdo. */
.msg.apagada .bolha {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
}
.msg-apagada {
  font-style: italic;
  font-size: 0.85rem;
}
/* Resposta citada (quote) dentro da bolha (D025). */
.msg-citacao {
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
  margin-bottom: 0.35rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--r-sm);
  background: rgba(127, 127, 127, 0.16);
  font-size: 0.78rem;
  color: inherit;
  opacity: 0.9;
  max-width: 100%;
}
.msg-citacao-bar {
  flex: 0 0 3px;
  border-radius: 2px;
  background: var(--info);
}
.msg.enviada .bolha .msg-citacao-bar {
  background: #fff;
}
.msg-citacao-txt {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
/* ---- Compositor (campo de resposta) — estilo pill clean ----------------- */
.form-resposta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.4rem 0.9rem 0.9rem;
  padding: 0.3rem 0.3rem 0.3rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-resposta:focus-within {
  border-color: var(--brand-grad-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-grad-1) 18%, transparent);
}
.form-resposta textarea {
  flex: 1;
  min-height: 24px;
  max-height: 140px;
  padding: 0.45rem 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  resize: none;
}
.form-resposta textarea:focus {
  outline: none;
  box-shadow: none;
}
.form-resposta textarea::placeholder {
  color: var(--text-muted);
}
.form-resposta .btn {
  flex: 0 0 auto;
  border-radius: var(--r-full);
  padding: 0.5rem 1rem;
  background: linear-gradient(140deg, var(--brand-grad-1), var(--brand-grad-2));
  color: #fff;
  border: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.form-resposta .btn:hover {
  filter: brightness(1.08);
}
/* Botão de anexo (clips) dentro do compositor */
.btn-anexo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: var(--r-full);
  color: var(--text-secondary);
  cursor: pointer;
}
.btn-anexo:hover {
  background: var(--surface-3);
  color: var(--text);
}

/* ---- Bolhas de mídia --------------------------------------------------- */
.msg-img {
  max-width: min(100%, 360px);
  border-radius: 10px;
  display: block;
  cursor: zoom-in;
}
.msg-audio,
.msg-video {
  display: block;
  max-width: min(100%, 330px);
}
.msg-video {
  border-radius: 10px;
}
/* Controle de velocidade acoplado ao player de vídeo (D026). */
.media-vel {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.3rem;
  max-width: 100%;
}
.media-vel audio,
.media-vel video {
  max-width: 100%;
}
/* Chip de velocidade (vídeo e player customizado). */
.vel-btn {
  min-width: 2.4rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1.5;
  cursor: pointer;
  transition:
    color 0.12s ease,
    border-color 0.12s ease,
    background 0.12s ease;
}
.vel-btn:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--info) 55%, var(--border));
  background: var(--surface-2);
}
.vel-btn:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}
.media-vel > .vel-btn {
  align-self: flex-end;
}
.msg.enviada .vel-btn {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}
.msg.enviada .vel-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* Player de áudio próprio: barra clara, velocidade dentro e baixar no topo. */
.audio-player {
  position: relative;
  width: min(340px, 100%);
  padding: 1.55rem 0.7rem 0.55rem;
  border-radius: 14px;
  background: #fff;
  color: #12151a;
}
.audio-baixar {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: var(--r-full);
  color: #6b7280;
  text-decoration: none;
}
.audio-baixar:hover {
  background: rgba(0, 0, 0, 0.07);
  color: #111;
}
.audio-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.audio-play {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border: 0;
  border-radius: var(--r-full);
  background: #12151a;
  color: #fff;
  cursor: pointer;
}
.audio-play:hover {
  background: #000;
}
.audio-time {
  flex: 0 0 auto;
  min-width: 2.4rem;
  font-size: 0.72rem;
  color: #6b7280;
  font-variant-numeric: tabular-nums;
}
.audio-seek {
  flex: 1 1 auto;
  min-width: 40px;
  height: 4px;
  appearance: none;
  -webkit-appearance: none;
  border-radius: var(--r-full);
  background: #d7dbe0;
  cursor: pointer;
}
.audio-seek::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #12151a;
}
.audio-seek::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: #12151a;
}
.audio-player .vel-btn {
  background: #f1f3f5;
  border-color: #e4e7ec;
  color: #5b6472;
}
.audio-player .vel-btn:hover {
  color: #12151a;
  border-color: #2563eb;
  background: #e8f0fe;
}
.msg-doc {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.5rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-3) 70%, transparent);
  color: var(--text);
  text-decoration: none;
  min-width: 200px;
}
.msg-doc:hover {
  background: var(--surface-3);
}
.msg-doc .doc-icone {
  font-size: 1.4rem;
  flex: 0 0 auto;
}
.msg-doc .doc-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.msg-doc .doc-info strong {
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-doc .doc-info .text-muted {
  font-size: 0.7rem;
}
.msg .bolha .legenda {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

@media (max-width: 860px) {
  .form-resposta {
    gap: 0.45rem;
    padding-left: 0.8rem;
  }
  .form-resposta .btn {
    padding: 0.5rem 0.9rem;
  }
  .form-resposta .btn .txt {
    display: none; /* no celular só o ícone, sem enrolação */
  }
}
.dica {
  font-size: 0.78rem;
  margin: 0 1.1rem 0.9rem;
}

/* Skip link (a11y) */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 0 0 var(--r-sm) 0;
}
.skip-link:focus {
  left: 0;
}

/* Rodapé da página pública (login/esqueci/redefinir) */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
