:root {
  --bg: #0e1316;
  --surface: #161d22;
  --surface-raised: #1b232a;
  --border: #29333a;
  --text: #e8ecee;
  --text-dim: #8b98a1;
  --accent: #e0a83c;
  --accent-dim: #7a5f26;
  --ok: #4caf7d;
  --ok-bg: rgba(76, 175, 125, 0.12);
  --danger: #e5615a;
  --danger-bg: rgba(229, 97, 90, 0.12);
  --pending: #5b7c99;
  --pending-bg: rgba(91, 124, 153, 0.12);
  --radius: 8px;
  --font-display: 'Oswald', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

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

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

/* ---------- SIDEBAR ---------- */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 24px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  font-size: 22px;
  color: var(--accent);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  font-family: var(--font-display);
}

.brand-text strong {
  font-size: 15px;
  letter-spacing: 0.04em;
}

.brand-text small {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: var(--surface-raised);
  color: var(--text);
}

.nav-item.active {
  background: var(--surface-raised);
  color: var(--accent);
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  position: relative;
}

.dot.qr { background: var(--accent); }
.dot.conectado {
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(76, 175, 125, 0.5);
  animation: pulse 2s infinite;
}
.dot.desconectado { background: var(--danger); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(76, 175, 125, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(76, 175, 125, 0); }
  100% { box-shadow: 0 0 0 0 rgba(76, 175, 125, 0); }
}

/* ---------- CONTENT ---------- */

.content {
  flex: 1;
  padding: 32px 40px;
  max-width: 1100px;
}

.panel { display: none; }
.panel.active { display: block; }

.panel-header { margin-bottom: 24px; }

.panel-header h1 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0 0 6px;
}

.subtitle {
  color: var(--text-dim);
  margin: 0;
  font-size: 13.5px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
}

.card h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 14px;
}

/* ---------- FORMS ---------- */

input[type="text"], input[type="file"], select, textarea {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 9px 11px;
  font-family: var(--font-body);
  font-size: 13.5px;
}

input[type="text"]:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-dim);
  outline-offset: 1px;
}

textarea { resize: vertical; font-family: var(--font-body); }

.grid-form {
  display: grid;
  grid-template-columns: 2fr 1.4fr 1.2fr 1.4fr auto;
  gap: 10px;
  align-items: center;
}

.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 560px;
}

.stacked-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.checkbox-line {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  color: var(--text) !important;
}

.checkbox-grupos {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
}

.checkbox-contatos {
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
}

.grupo-secao {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0 6px;
  margin-top: 4px;
  border-bottom: 1px solid var(--border);
}

.grupo-secao:first-child { margin-top: 0; }

.grupo-secao .titulo {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.grupo-secao .acoes a {
  font-size: 12.5px;
  color: var(--accent);
  cursor: pointer;
  margin-left: 10px;
  text-decoration: underline;
}

.contato-linha {
  padding: 7px 0;
}

.contato-linha .telefone-mini {
  color: var(--text-dim);
  font-size: 12.5px;
  margin-left: 6px;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.hint {
  color: var(--text-dim);
  font-size: 12px;
  margin: 4px 0 0;
}

.hint code, .subtitle code {
  background: var(--surface-raised);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  color: var(--accent);
}

/* ---------- BUTTONS ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 6px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s ease;
}

.btn:hover { filter: brightness(1.15); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #201505;
  font-weight: 600;
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
}

.btn-large {
  padding: 12px 20px;
  font-size: 14px;
  align-self: flex-start;
}

/* ---------- TABLE ---------- */

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-body);
}

td.mono, .mono { font-family: var(--font-mono); font-size: 12.5px; }

tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
}

.badge-sim, .badge-enviado, .badge-conectado, .badge-concluida { background: var(--ok-bg); color: var(--ok); }
.badge-nao, .badge-falhou, .badge-desconectado { background: var(--danger-bg); color: var(--danger); }
.badge-pendente, .badge-enviando, .badge-qr, .badge-pausado { background: var(--pending-bg); color: var(--pending); }
.badge-cancelada, .badge-cancelado, .badge-sem_resposta { background: rgba(139, 152, 161, 0.15); color: var(--text-dim); }

.fieldset-timing {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px 6px;
  margin: 0;
}

.fieldset-timing legend {
  font-size: 12px;
  color: var(--text-dim);
  padding: 0 6px;
}

.timing-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.timing-row label {
  font-size: 12.5px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.timing-pair {
  display: flex;
  align-items: center;
  gap: 8px;
}

.timing-pair span {
  color: var(--text-dim);
  font-size: 12px;
}

.timing-row input[type="number"] {
  width: 80px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12.5px;
  padding: 0;
}

/* ---------- CONNECTION PANEL ---------- */

.connection-card { text-align: center; padding: 32px; }

.conn-state img#qr-image {
  width: 260px;
  height: 260px;
  border-radius: 10px;
  border: 6px solid #fff;
  margin-top: 16px;
}

.qr-instructions { max-width: 420px; margin: 0 auto; color: var(--text-dim); }

.ok-message { color: var(--ok); font-size: 16px; font-weight: 600; margin-bottom: 16px; }

.notice-card ul { margin: 10px 0 0; padding-left: 20px; color: var(--text-dim); }
.notice-card li { margin-bottom: 6px; }
.notice-card strong { color: var(--text); }

.preview {
  background: var(--surface-raised);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13px;
  white-space: pre-wrap;
  color: var(--text-dim);
  min-height: 20px;
}

#import-resultado, #campanha-resultado { margin-top: 12px; font-size: 13px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .content { padding: 20px; }
  .grid-form { grid-template-columns: 1fr; }
}

/* ---------- LOGIN ---------- */

body.pagina-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-shell {
  width: 100%;
  max-width: 380px;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
}

.login-card .stacked-form {
  max-width: none;
}

.erro-login {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
  margin: 0;
}

/* ---------- MODAL (trocar senha, avisos) ---------- */

.modal-fundo {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-caixa {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 360px;
}

.modal-caixa h2 {
  font-family: var(--font-display);
  font-size: 17px;
  margin: 0 0 6px;
}

/* ---------- ADMIN: gerenciar clientes ---------- */

.senha-gerada-caixa {
  background: var(--surface-raised);
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.senha-gerada-caixa .valor {
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--accent);
  user-select: all;
  cursor: pointer;
}

/* ---------- CONVERSAS (caixa de entrada) ---------- */

.conversas-layout {
  display: flex;
  gap: 20px;
  align-items: stretch;
  min-height: 520px;
}

.conversas-lista {
  width: 300px;
  flex-shrink: 0;
  padding: 0;
  overflow-y: auto;
  max-height: 640px;
}

.conversa-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  cursor: pointer;
  color: var(--text);
}

.conversa-item:hover { background: var(--surface-raised); }
.conversa-item.ativa { background: var(--surface-raised); border-left: 3px solid var(--accent); }

.conversa-item .linha-topo {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.conversa-item .nome { font-weight: 600; }
.conversa-item .nome.nao-lida::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 7px;
}

.conversa-item .hora { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.conversa-item .preview {
  font-size: 13.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversas-thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.thread-header {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.thread-header .mono { color: var(--text-dim); font-size: 13px; }

.thread-mensagens {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 4px 16px;
  max-height: 440px;
}

.msg-bubble {
  max-width: 72%;
  padding: 9px 14px;
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.45;
}

.msg-bubble .meta {
  display: block;
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.65;
}

.msg-bubble.recebida {
  align-self: flex-start;
  background: var(--surface-raised);
  border-bottom-left-radius: 3px;
}

.msg-bubble.enviada {
  align-self: flex-end;
  background: var(--accent-dim);
  color: var(--text);
  border-bottom-right-radius: 3px;
}

.thread-input {
  display: flex;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.thread-input input {
  flex: 1;
}

.thread-input-fechada {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.thread-input-fechada select {
  margin-bottom: 10px;
}

@media (max-width: 760px) {
  .conversas-layout { flex-direction: column; min-height: 0; }
  .conversas-lista { width: 100%; max-height: 300px; }
}

/* ---------- Ações em lote (contatos) ---------- */

.lote-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.lote-toolbar #lote-contador {
  color: var(--text-dim);
  font-weight: 600;
  white-space: nowrap;
}

.lote-acao {
  display: flex;
  gap: 6px;
  align-items: center;
}
