:root {
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-light: color-mix(in srgb, var(--primary) 14%, #ffffff);
  --ink: #0f172a;
  --ink-soft: #334155;
  --paper: #ffffff;
  --bg: color-mix(in srgb, var(--primary) 4%, #f8fafc);
  --bg-chat: color-mix(in srgb, var(--primary) 9%, #f3f6fb);
  --border: #dde4f0;
  --muted: #64748b;
  --bubble-in: #ffffff;
  --bubble-out: color-mix(in srgb, var(--primary) 16%, #ffffff);
  --bubble-out-border: color-mix(in srgb, var(--primary) 32%, #ffffff);
  --topnav-height: 58px;
  --success: #1f9d55;
  --danger: #c0392b;
  --warning: #b8860b;
  --radius: 10px;
  --sidebar-width: 340px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

a { color: inherit; text-decoration: none; }

.icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.icon-inline { display: inline-flex; align-items: center; gap: 8px; }
.icon-inline .icon { margin-right: 8px; }

img { max-width: 100%; display: block; }

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* ---------- Barra de navegação principal (topo) ---------- */
.topnav {
  height: var(--topnav-height);
  flex-shrink: 0;
  background: linear-gradient(90deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  position: relative;
  z-index: 50;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.18);
}

.topnav-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.2px;
  white-space: nowrap;
  color: #fff;
}

.topnav-logo { height: 34px; width: auto; max-width: 120px; border-radius: 8px; object-fit: contain; background: rgba(255,255,255,0.14); padding: 3px; }
.login-brand img { max-width: 36px; max-height: 36px; object-fit: contain; }
.topnav-brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.topnav-brand-text strong { font-size: 16px; font-weight: 800; }
.topnav-brand-text small { font-size: 11px; font-weight: 600; opacity: .8; letter-spacing: .2px; }

.topnav-brand .icon { background: rgba(255,255,255,0.18); border-radius: 10px; padding: 7px; box-sizing: content-box; }

.topnav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.nav-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 13px;
  border-radius: 10px;
  color: rgba(255,255,255,0.86);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s ease, color .15s ease;
}

.nav-item:hover { background: rgba(255,255,255,0.14); color: #fff; }
.nav-item.active { background: #fff; color: var(--primary-dark); }

.nav-item .badge-dot {
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-dd { position: relative; }

.nav-dd-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.22);
  padding: 6px;
  z-index: 60;
}

.nav-dd-menu.open { display: block; }

.nav-dd-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.nav-dd-menu a:hover { background: var(--primary-light); color: var(--primary-dark); }
.nav-dd-menu a.active { background: var(--primary-light); color: var(--primary-dark); }

.topnav-right { display: flex; align-items: center; gap: 10px; margin-left: auto; position: relative; }

.topnav-icon {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
}

.topnav-icon:hover { background: rgba(255,255,255,0.14); }
.topnav-icon .badge-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--primary);
}

.topnav-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.45);
}

.topnav-avatar img { width: 100%; height: 100%; object-fit: cover; }

.topnav-burger {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: rgba(255,255,255,0.14);
  color: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

@media (max-width: 1100px) {
  .topnav { gap: 10px; padding: 0 12px; }
  .topnav-burger { display: inline-flex; }
  .topnav-links {
    display: none;
    position: absolute;
    top: var(--topnav-height);
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 10px 12px 14px;
    background: var(--primary-dark);
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.3);
  }
  .topnav-links.open { display: flex; }
  .nav-item { height: 42px; }
  .nav-dd-menu { position: static; box-shadow: none; margin: 4px 0 0 12px; }
}

/* ---------- Conteúdo principal ---------- */
.main-content {
  flex: 1;
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-header {
  padding: 16px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.panel-body.no-pad { padding: 0; }

/* ---------- Duas colunas (lista + thread) ---------- */
.two-pane {
  display: flex;
  width: 100%;
  height: 100%;
  min-width: 0;
}

.list-pane {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--paper);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.list-pane-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.list-pane-header h2 {
  font-size: 16px;
  margin: 0 0 10px;
}

.list-pane-body {
  flex: 1;
  overflow-y: auto;
}

.thread-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  background-image: radial-gradient(rgba(0,0,0,0.02) 1px, transparent 1px);
  background-size: 18px 18px;
  min-width: 0;
}

.thread-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  flex-direction: column;
  gap: 8px;
}

/* ---------- Context switcher (contas WhatsApp) ---------- */
.context-switcher {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
}

.context-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 13px;
  white-space: nowrap;
  background: var(--paper);
  color: var(--ink-soft);
}

.context-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.context-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ---------- Conversation / channel rows ---------- */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border-radius: 999px;
  padding: 8px 14px;
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 14px;
}

.row-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #f0ebe9;
  cursor: pointer;
  align-items: center;
  position: relative;
}

.row-item:hover { background: var(--bg); }
.row-item.selected { background: var(--primary-light); }

.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--primary-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
  font-size: 15px;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.lg { width: 84px; height: 84px; font-size: 26px; }

.row-content { flex: 1; min-width: 0; }

.row-top { display: flex; justify-content: space-between; gap: 8px; }

.row-title {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }

.row-preview {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.row-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; }

.unread-badge {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.assignee-tag {
  font-size: 11px;
  background: var(--bg);
  color: var(--ink-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

/* ---------- Thread header ---------- */
.thread-header {
  padding: 12px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.thread-header .info { flex: 1; min-width: 0; }
.thread-header .name { font-weight: 700; font-size: 15px; }
.thread-header .sub { font-size: 12px; color: var(--muted); }

/* ---------- Message bubbles ---------- */
.messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 6%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bubble-row { display: flex; }
.bubble-row.out { justify-content: flex-end; }
.bubble-row.in { justify-content: flex-start; }

/* Foto de quem enviou — só aparece nas mensagens recebidas */
.bubble-avatar {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-dark);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  align-self: flex-start;
  margin: 3px 8px 0 0;
}
.bubble-row.in .bubble-avatar { display: flex; }
.bubble-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Separador de data entre dias + chip flutuante ao rolar (estilo WhatsApp) */
.day-divider { display: flex; justify-content: center; margin: 10px 0 6px; }
.day-divider span, .day-chip {
  background: rgba(255,255,255,0.92);
  color: var(--ink-soft);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
}
.system-message { display: flex; justify-content: center; margin: 4px 0; }
.system-message span {
  background: rgba(0,0,0,0.045);
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  text-align: center;
  max-width: 80%;
}

.messages-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.day-chip {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.day-chip.visible { opacity: 1; }

.bubble {
  max-width: 65%;
  padding: 8px 12px;
  border-radius: 10px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
  position: relative;
  font-size: 14.2px;
  line-height: 1.4;
  margin: 3px 0;
}

.bubble.in { background: var(--bubble-in); border: 1px solid var(--border); border-top-left-radius: 2px; }
.bubble.out { background: var(--bubble-out); border: 1px solid var(--bubble-out-border); border-top-right-radius: 2px; }

.bubble .sender-name {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 2px;
}

.bubble .bubble-media { margin-bottom: 4px; border-radius: 8px; overflow: hidden; }
.bubble .bubble-media img, .bubble .bubble-media video { max-width: 100%; border-radius: 8px; }
.bubble audio { width: 220px; }

.bubble-quote {
  display: block;
  background: rgba(0,0,0,0.045);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 12.5px;
  line-height: 1.3;
  cursor: pointer;
}
.bubble-quote strong { display: block; color: var(--primary); font-size: 11.5px; }
.bubble-quote span { color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

.bubble-row.flash .bubble { animation: mz-flash 1.2s ease; }
@keyframes mz-flash {
  0% { box-shadow: 0 0 0 2px var(--primary); }
  100% { box-shadow: none; }
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 3px;
}

.bubble-reply-btn {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  opacity: 0;
  transition: opacity .12s ease;
}
.bubble-row:hover .bubble-reply-btn { opacity: 1; }

.reply-preview {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  padding: 6px 10px;
  margin: 0 20px 8px;
  font-size: 12.5px;
}
.reply-preview.open { display: flex; }
.reply-preview .reply-preview-text { min-width: 0; overflow: hidden; }
.reply-preview .reply-preview-text strong { display: block; color: var(--primary); font-size: 11.5px; }
.reply-preview .reply-preview-text span { color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* Pré-visualização de anexo (imagem/áudio/arquivo) antes de confirmar o envio */
.attach-preview {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0 20px 8px;
}
.attach-preview.open { display: flex; }
.attach-preview-content { min-width: 0; flex: 1; display: flex; align-items: center; }
.attach-preview-content img { max-height: 64px; max-width: 140px; border-radius: 6px; object-fit: cover; }
.attach-preview-content audio { width: 100%; max-width: 260px; height: 32px; }
.attach-preview-file { font-size: 12.5px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-icon.read { color: #4fa3e3; }
.status-icon.failed { color: var(--danger); }

/* ---------- Composer ---------- */
.composer {
  padding: 12px 20px;
  background: var(--paper);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- @menção ---------- */
.mention-picker {
  position: absolute;
  bottom: 100%;
  left: 20px;
  right: 20px;
  margin-bottom: 6px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  overflow: hidden;
  z-index: 20;
}
.mention-picker-item { padding: 9px 14px; font-size: 13.5px; cursor: pointer; }
.mention-picker-item:hover { background: var(--bg); }
.mention { color: var(--primary); font-weight: 600; }

.composer input[type="text"], .composer textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  resize: none;
  font-family: inherit;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  flex-shrink: 0;
}

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

.send-btn {
  background: var(--primary);
  color: #fff;
}

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

/* ---------- Buttons / forms genéricos ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.btn:hover { background: var(--primary-dark); }
.btn.btn-outline { background: transparent; border-color: var(--border); color: var(--ink); }
.btn.btn-outline:hover { background: var(--bg); }
.btn.btn-outline.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.btn-danger { background: var(--danger); }
.btn.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.form-input, select.form-input, textarea.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: var(--paper);
}

.form-input:focus { border-color: var(--primary); }

/* Tom Select (busca em selects de base de contato) — reveste o look padrão
   da lib pra combinar com .form-input do resto do app. */
.ts-wrapper.single .ts-control, .ts-wrapper .ts-control {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--paper);
  font-size: 14px;
  font-family: inherit;
  box-shadow: none;
}
.ts-wrapper.focus .ts-control { border-color: var(--primary); box-shadow: none; }
.ts-dropdown {
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  /* Quando aberto dentro de um .dropdown-panel (z-index:40) e movido pro
     <body> (dropdownParent), sem isso ele fica escondido atrás do painel.
     !important porque o CSS do Tom Select carrega depois do nosso (via
     extra_head) e também define z-index nessa mesma classe. */
  z-index: 300 !important;
}
.ts-dropdown .ts-dropdown-content { padding: 4px; }
.ts-dropdown .option, .ts-dropdown .no-results { padding: 8px 10px; border-radius: 6px; }
.ts-dropdown .option.active { background: var(--primary-light); color: var(--ink); }
.ts-control > input::placeholder { color: #9c9490; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-soft); }

.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

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

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table tbody tr:hover { background: var(--bg); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge-success { background: #e4f6e9; color: var(--success); }
.badge-warning { background: #fbf0d9; color: var(--warning); }
.badge-danger { background: #fbe3e0; color: var(--danger); }
.badge-muted { background: var(--bg); color: var(--muted); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  padding: 20px;
}

.login-card {
  background: var(--paper);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  text-align: center;
}

.login-brand { display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 14px; background: var(--primary); color: #fff; margin: 0 auto 16px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p.subtitle { color: var(--muted); font-size: 13px; margin: 0 0 24px; }
.login-card form { text-align: left; }

/* ---------- Notificações / dropdown ---------- */
.dropdown-panel {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  min-width: 220px;
  z-index: 40;
  overflow: hidden;
}

.dropdown-panel.open { display: block; }

.dropdown-panel a, .dropdown-panel button.link-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 16px;
  font-size: 13.5px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink);
}

.dropdown-panel a:hover, .dropdown-panel button.link-btn:hover { background: var(--bg); }
.dropdown-panel hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

.notif-panel {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  width: 320px;
  max-height: 420px;
  overflow-y: auto;
  z-index: 40;
}

.notif-panel.open { display: block; }

.notif-item {
  display: block;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink);
  text-decoration: none;
  overflow-wrap: anywhere;
}

a.notif-item:hover { background: var(--bg); }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--primary-light); font-weight: 600; }
a.notif-item.unread:hover { background: var(--primary-light); filter: brightness(.97); }

/* ---------- Feed social (estilo Instagram) ---------- */
.feed-wrap { max-width: 470px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }

.composer-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.post-card { background: var(--paper); border: 1px solid var(--border); border-radius: 3px; overflow: hidden; }

.post-head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; }
.post-head .avatar { width: 32px; height: 32px; font-size: 13px; }
.post-head .name { font-weight: 600; font-size: 13.5px; }
.post-head .name a:hover { text-decoration: underline; }
.post-head .time { font-size: 12.5px; color: var(--muted); }

.post-media {
  position: relative;
  width: 100%;
  max-height: 600px;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
/* Mostra a imagem/vídeo inteiro, sem cortar (nada de aspect-ratio fixo
   "quadrado" cortando infográficos e imagens compridas) — só limita a
   altura na timeline; pra ver em tamanho real é só clicar (lightbox). */
.post-media img, .post-media video { width: 100%; height: auto; max-height: 600px; object-fit: contain; display: block; }
.post-media img { cursor: zoom-in; }
.post-media.is-audio { max-height: none; background: var(--bg); padding: 20px 16px; }
.post-media.is-audio audio { width: 100%; }

/* ---------- Lightbox genérico (clique pra ver imagem em tela cheia) ---------- */
.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox-overlay.open { display: flex; }
.lightbox-overlay img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }

.post-actions { display: flex; align-items: center; gap: 4px; padding: 8px 6px 0; }
.post-actions .icon-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  color: var(--ink);
  cursor: pointer;
  border-radius: 50%;
  transition: transform .1s ease, color .15s ease;
}
.post-actions .icon-action:hover { color: var(--ink-soft); }
.post-actions .icon-action:active { transform: scale(0.88); }
.post-actions .icon-action.liked { color: var(--primary); }

.post-likes { padding: 2px 16px 0; font-size: 13.5px; font-weight: 600; }
.post-caption { padding: 6px 16px 0; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.post-caption .cap-name { font-weight: 600; margin-right: 5px; }
.post-caption .cap-name:hover { text-decoration: underline; }

.comments-list { padding: 8px 16px 4px; display: flex; flex-direction: column; gap: 6px; }
.comment-item { font-size: 14px; line-height: 1.4; }
.comment-item .cm-name { font-weight: 600; margin-right: 5px; }
.comment-item .cm-name:hover { text-decoration: underline; }
.comment-item.reply { margin-left: 26px; margin-top: 2px; }
.comment-actions { display: flex; gap: 14px; margin: 2px 0 4px; }
.replies-list { margin-top: 2px; display: flex; flex-direction: column; gap: 2px; }

.comment-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.comment-composer input[type="text"] {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  background: transparent;
}
.comment-composer button {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}
.comment-composer button:disabled { color: var(--muted); cursor: default; }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.link-btn:hover { color: var(--ink); }

/* ---------- Campanhas / progresso ---------- */
.progress-bar { width: 100%; height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--primary); transition: width .3s ease; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 16px 0; }
.stat-box { background: var(--bg); border-radius: 10px; padding: 14px; text-align: center; }
.stat-box .value { font-size: 22px; font-weight: 800; color: var(--primary); }
.stat-box .label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; }

/* ---------- QR / conexões ---------- */
.qr-box {
  background: #fff;
  padding: 18px;
  border-radius: 14px;
  display: inline-flex;
  border: 1px solid var(--border);
}

.qr-box img { width: 240px; height: 240px; }

.instance-card { display: flex; align-items: center; gap: 14px; }
.instance-card .color-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }

/* ---------- Permissões ---------- */
.perm-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.perm-search { max-width: 320px; width: 100%; }
.perm-legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.perm-legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--border); }
.perm-legend .lv-view::before { background: #f59e0b; }
.perm-legend .lv-manage::before { background: var(--primary); }

.perm-user {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 14px;
  overflow: hidden;
}

.perm-user-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #f8fafe 0%, #fff 100%);
}

.perm-person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.perm-person strong { display: block; font-size: 14.5px; }
.perm-person > div > span { font-size: 12.5px; color: var(--muted); }

.perm-presets { position: relative; }
.perm-presets summary { list-style: none; cursor: pointer; }
.perm-presets summary::-webkit-details-marker { display: none; }
.perm-presets-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 250px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.18);
  padding: 6px;
  z-index: 20;
}
.perm-presets-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  color: var(--ink);
}
.perm-presets-menu button:hover { background: var(--primary-light); color: var(--primary-dark); }

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  background: var(--paper);
}

.perm-cell { background: var(--paper); padding: 14px 18px; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); border-right: 1px solid var(--border); }
.perm-cell .name { font-size: 13.5px; font-weight: 700; color: var(--ink); }
.perm-cell .desc { font-size: 12px; color: var(--muted); line-height: 1.4; min-height: 34px; }

.perm-level {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  align-self: flex-start;
}
.perm-level input { position: absolute; opacity: 0; pointer-events: none; }
.perm-level label {
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
  cursor: pointer;
  background: var(--paper);
  border-right: 1px solid var(--border);
  user-select: none;
}
.perm-level label:last-of-type { border-right: none; }
.perm-level input:checked + label.lv-none { background: #eef1f6; color: var(--ink-soft); }
.perm-level input:checked + label.lv-view { background: #fef3c7; color: #92400e; }
.perm-level input:checked + label.lv-manage { background: var(--primary); color: #fff; }
.perm-level input:focus-visible + label { outline: 2px solid var(--primary); outline-offset: -2px; }

.perm-savebar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.08);
}

/* ---------- Utilities ---------- */
.text-muted { color: var(--muted); }
.mt-0 { margin-top: 0; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }

.messages-framework {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
}

.toast {
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  :root { --sidebar-width: 280px; }
}

/* ---------- Painel lateral "Dados do grupo" ---------- */
.side-drawer {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 360px;
  max-width: 100%;
  background: var(--paper);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0,0,0,0.10);
  transform: translateX(105%);
  transition: transform .2s ease;
  z-index: 25;
  overflow-y: auto;
}
.side-drawer.open { transform: none; }

.group-info-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--paper); z-index: 1; }
.group-info-hero { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px 16px 16px; border-bottom: 1px solid var(--border); text-align: center; }
.avatar.xl { width: 110px; height: 110px; font-size: 40px; margin-bottom: 8px; }
.group-info-title { font-size: 18px; font-weight: 700; }
.group-info-section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.group-info-label { font-size: 12px; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: .3px; margin-bottom: 6px; }
.group-members { list-style: none; margin: 0; padding: 0 0 12px; }
.group-members li { display: flex; align-items: center; gap: 12px; padding: 8px 16px; }
.group-members li:hover { background: var(--bg); }
.member-main { flex: 1; min-width: 0; }
.member-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-phone { font-size: 12px; color: var(--muted); }
.member-badge { font-size: 11px; color: var(--success); border: 1px solid var(--success); border-radius: 6px; padding: 1px 6px; flex-shrink: 0; }

/* ---------- Segurança / usuários: componentes de uso fácil ---------- */
[x-cloak] { display: none !important; }
.page-sub { font-size: 13px; color: var(--muted); margin-top: 3px; max-width: 70ch; }
.panel-header { flex-wrap: wrap; }
.card.no-pad { padding: 0; overflow: hidden; }

.chip { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; background: #eef2f9; color: var(--ink-soft); font-size: 12px; font-weight: 600; margin: 2px 4px 2px 0; }
.chip-blue { background: var(--primary-light); color: var(--primary-dark); }
.chip-warn { background: #fef3c7; color: #92400e; }
a.chip:hover { background: var(--primary-light); color: var(--primary-dark); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--paper); }
.seg button { border: none; background: none; padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--primary); color: #fff; }
.seg-n { opacity: .75; margin-left: 4px; font-weight: 500; }

.row-actions-wrap { display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-actions-wrap form { margin: 0; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.table td { vertical-align: middle; }
.btn-danger-text { color: var(--danger); }
.btn-pulse { box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.22); }

.perm-person .avatar { flex-shrink: 0; }
.perm-person > div > span { display: block; }
.perm-group-title { padding: 10px 18px; font-size: 11.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--primary-dark); background: #f3f7ff; border-top: 1px solid var(--border); }
.perm-note { padding: 18px; display: flex; align-items: center; gap: 10px; color: var(--ink-soft); font-size: 13.5px; }
.perm-foot { padding: 10px 18px; background: #fffbeb; color: #92400e; font-size: 13px; border-top: 1px solid #fde68a; }
.perm-actions { display: flex; align-items: center; gap: 8px; }
.perm-presets-menu button small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; font-weight: 400; }
.perm-user { scroll-margin-top: 14px; }
.perm-user:target { box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.28); }
.perm-legend .lv-none::before { background: #cbd5e1; }

.form-sections { max-width: 860px; display: flex; flex-direction: column; gap: 16px; }
.form-card h2 { font-size: 15px; margin: 0 0 14px; }
.form-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 18px; }
.field-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
.check-row { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; cursor: pointer; border-bottom: 1px solid var(--border); }
.check-row:last-of-type { border-bottom: none; }
.check-row input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--primary); }
.check-row small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; font-weight: 400; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.alert { padding: 12px 16px; border-radius: 10px; font-size: 13.5px; }
.alert-danger { background: #fee2e2; color: #991b1b; }

.sector-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.sector-card { display: flex; flex-direction: column; gap: 12px; }
.sector-card header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sector-card h3 { margin: 0; font-size: 16px; }
.sector-line { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 13px; }
.sector-line .lbl { width: 64px; font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.sector-card footer { display: flex; gap: 8px; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); }
.sector-card footer form { margin: 0; }

.people-list { display: flex; flex-direction: column; }
.people-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.people-row:last-child { border-bottom: none; }

/* ---------- Personalização ---------- */
.custom-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; max-width: 1180px; }
.custom-layout .form-sections { max-width: none; }
.custom-preview { position: sticky; top: 0; }
.custom-preview h2 { font-size: 15px; margin: 0 0 12px; }
.color-field { display: flex; gap: 10px; align-items: center; }
.color-field input[type=color] { width: 46px; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: 10px; background: var(--paper); cursor: pointer; }
.color-field .form-input { max-width: 140px; font-family: ui-monospace, Menlo, Consolas, monospace; text-transform: uppercase; }
.swatches { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; font-size: 13px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); cursor: pointer; }
.swatch:hover { transform: scale(1.1); }
.asset-current { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.asset-current img { max-height: 48px; max-width: 160px; border: 1px solid var(--border); border-radius: 8px; padding: 4px; background: #fff; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.pv-nav { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; color: #fff; }
.pv-logo { height: 28px; width: auto; max-width: 90px; object-fit: contain; border-radius: 6px; background: rgba(255,255,255,.14); padding: 2px; }
.pv-icon { width: 30px; height: 30px; border-radius: 9px; background: rgba(255,255,255,.18); display: inline-flex; align-items: center; justify-content: center; }
.pv-name { display: flex; flex-direction: column; line-height: 1.15; }
.pv-name strong { font-size: 14px; }
.pv-name small { font-size: 10.5px; opacity: .85; }
.pv-active { margin-left: auto; background: #fff; color: #1e293b; padding: 5px 10px; border-radius: 8px; font-size: 12px; font-weight: 700; }
.pv-body { padding: 14px 4px; display: flex; flex-direction: column; gap: 12px; }
.pv-bubble { align-self: flex-end; border: 1px solid; padding: 9px 12px; border-radius: 12px 12px 2px 12px; font-size: 13px; }
.pv-row { display: flex; align-items: center; gap: 10px; }
.pv-btn { border: none; color: #fff; padding: 8px 14px; border-radius: 9px; font-weight: 700; font-size: 13px; font-family: inherit; }
.pv-chip { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
@media (max-width: 980px) { .custom-layout { grid-template-columns: 1fr; } .custom-preview { position: static; } }

/* ---------- Alinhamento geral (todas as telas) ---------- */
.panel-header { min-height: 72px; align-items: center; }
.panel-body { padding: 24px; }
.panel-body > .card, .panel-body > .form-sections, .panel-body > form.card { margin-left: 0; }

/* conteúdo que antes se centralizava sozinho agora acompanha o título da página */
.panel .dem-page, .panel .dm { margin: 0; max-width: none; padding: 0; }
.feed-wrap { max-width: 560px; margin: 0 auto; }

/* chat: cabeçalhos da lista e da conversa com a mesma altura e itens centralizados */
.list-pane-header.flex-between { min-height: 72px; display: flex; align-items: center; }
.list-pane-header.flex-between h2 { margin: 0; }
.thread-header { min-height: 72px; }
.thread-header .info { display: flex; flex-direction: column; justify-content: center; min-height: 46px; }
.thread-header .sub { min-height: 15px; line-height: 15px; }

/* estados vazios centralizados dentro da área */
.empty-state { grid-column: 1 / -1; width: 100%; text-align: center; padding: 56px 20px; }

/* campos de arquivo no padrão do sistema */
input[type=file] { padding: 7px 8px; font-size: 13px; color: var(--ink-soft); background: var(--paper); }
input[type=file]::file-selector-button { border: 0; background: var(--primary-light); color: var(--primary-dark); padding: 7px 14px; border-radius: 8px; font-weight: 700; margin-right: 10px; cursor: pointer; font-family: inherit; }
input[type=file]::file-selector-button:hover { background: color-mix(in srgb, var(--primary) 24%, #fff); }

/* texto de apoio dentro de cartões */
.card > p, .form-card > p { font-size: 13.5px; line-height: 1.55; color: var(--ink-soft); }
.card > p.text-muted, .form-card > p.text-muted { color: var(--muted); }

/* tabelas largas rolam em vez de cortar o texto */
.dm-table-wrap { overflow-x: auto; }
.card.no-pad { overflow-x: auto; }
.table th { white-space: nowrap; }

/* formulários: a primeira coluna alinha com o título */
.panel-body > .card:first-child { margin-top: 0; }

/* celular: lista de conversas em cima, conversa embaixo (em vez de duas colunas espremidas) */
@media (max-width: 800px) {
  .two-pane { flex-direction: column; }
  .list-pane { width: 100%; height: 40%; border-right: 0; border-bottom: 1px solid var(--border); }
  .thread-pane { min-height: 0; flex: 1; }
  .panel-header { padding: 14px 16px; }
  .panel-body { padding: 16px; }
}
.btn { white-space: nowrap; }
.panel-header .flex { flex-wrap: wrap; }
.card .table { min-width: 560px; }
.card:has(> .table) { overflow-x: auto; }

/* permissões: cartões de pessoa em sanfona */
.perm-user-head { cursor: pointer; user-select: none; }
.perm-user-head:hover { background: #f6f9ff; }
.perm-user-head:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.perm-chevron { display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; border-radius: 8px; color: var(--muted); transition: transform .18s ease; flex-shrink: 0; }
.perm-chevron.open { transform: rotate(180deg); color: var(--primary); }
.perm-bulk { display: flex; gap: 8px; }
.perm-user-head { border-bottom: 0; }
.perm-user [x-show] > .perm-group-title:first-child { border-top: 1px solid var(--border); }
