* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1420;
  --bg2: #171d2b;
  --bg3: #1e2636;
  --line: #2a3446;
  --txt: #e8edf5;
  --muted: #8a97ad;
  --accent: #25d366;
  --accent2: #128c7e;
  --blue: #4f8cff;
  --read: #e63946;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* LOGIN */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 16px; padding: 40px; width: 340px; text-align: center;
}
.login-box .logo { font-size: 44px; }
.login-box h1 { font-size: 22px; margin: 10px 0 2px; }
.login-box p { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.login-box input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg3); color: var(--txt); font-size: 15px; margin-bottom: 12px;
}
.login-box button {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--accent); color: #04210f; font-weight: 700; font-size: 15px; cursor: pointer;
}
.erro { color: var(--read); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* HEADER */
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 28px; background: var(--bg2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo-sm { font-size: 28px; }
.brand strong { font-size: 16px; }
.brand .sub { color: var(--muted); font-size: 12px; }
.header-right { display: flex; align-items: center; gap: 14px; }
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #b44; box-shadow: 0 0 8px #b44; }
.dot.on { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.btn-toggle {
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg3); color: var(--txt); cursor: pointer; font-weight: 600; font-size: 13px;
}
.btn-toggle.off { background: #3a2020; border-color: #5a2a2a; color: #ff9a9a; }
.btn-ghost {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); cursor: pointer; font-size: 13px;
}
.btn-ghost:hover { color: var(--txt); border-color: var(--blue); }

/* CARDS */
.cards {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  padding: 24px 28px 8px;
}
.card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px;
}
.card-ico { font-size: 20px; margin-bottom: 8px; }
.card-val { font-size: 30px; font-weight: 800; }
.card-lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* TABS */
.tabs { display: flex; gap: 8px; padding: 16px 28px 0; }
.tab {
  padding: 10px 20px; border: none; background: transparent; color: var(--muted);
  font-size: 15px; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--txt); border-bottom-color: var(--accent); }

.tab-panel { display: none; padding: 18px 28px 40px; }
.tab-panel.active { display: block; }

/* CONVERSAS */
.split { display: grid; grid-template-columns: 340px 1fr; gap: 16px; min-height: 60vh; }
.lista-conv, .detalhe {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column;
}
.lista-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 14px;
}
.conversas { overflow-y: auto; max-height: 62vh; }
.conv {
  padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.conv:hover { background: var(--bg3); }
.conv.sel { background: var(--bg3); border-left: 3px solid var(--accent); }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-nome { font-weight: 600; font-size: 14px; }
.conv-hora { color: var(--muted); font-size: 11px; white-space: nowrap; }
.conv-prev { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-badge { display: inline-block; font-size: 10px; background: var(--accent2); color: #04210f; padding: 2px 6px; border-radius: 6px; margin-left: 6px; }
.conv-badge.site { background: var(--blue); color: #06203f; }
.conv-badge.humano { background: #c8891f; color: #2a1a00; }

.vazio { padding: 40px; color: var(--muted); text-align: center; }
.detalhe-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.thread {
  padding: 18px; overflow-y: auto; max-height: 58vh; display: flex; flex-direction: column; gap: 10px;
  background: #0c111b;
}
.msg { max-width: 65%; padding: 9px 13px; border-radius: 12px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; }
.msg.user { align-self: flex-start; background: var(--bg3); border-bottom-left-radius: 4px; }
.msg.assistant { align-self: flex-end; background: #075e54; border-bottom-right-radius: 4px; }
.msg-time { display: block; font-size: 10px; color: var(--muted); margin-top: 4px; }

/* FORM */
.form { max-width: 900px; }
.form h3 { margin: 26px 0 12px; font-size: 16px; color: var(--blue); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field textarea, .field select {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; color: var(--txt); font-size: 14px; font-family: inherit; resize: vertical;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--blue); }
.form-actions { display: flex; align-items: center; gap: 14px; margin-top: 24px; }
.btn-primary {
  background: var(--accent); color: #04210f; border: none; border-radius: 10px;
  padding: 12px 26px; font-weight: 700; font-size: 15px; cursor: pointer;
}
.save-msg { color: var(--accent); font-size: 14px; }

/* CONEXAO */
.box {
  margin-top: 18px; padding: 18px 20px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg2);
}
.box h4 { font-size: 15px; margin-bottom: 10px; }
.dica { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 6px 0; }
.dica.aviso { color: #ffcf7a; }
.dica code, code {
  background: var(--bg3); padding: 1px 6px; border-radius: 5px;
  font-family: Consolas, monospace; font-size: 12px;
}
.webhook-box {
  margin-top: 16px; padding: 14px 16px; border: 1px dashed var(--blue);
  border-radius: 10px; background: #0c111b;
}
.webhook-linha { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.mono { font-family: Consolas, monospace; font-size: 12px; color: var(--accent); word-break: break-all; }
small.dica { display: block; margin-top: 6px; }

.wa-status { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 6px 0 4px; }
.qr-area { margin: 14px 0; text-align: center; }
.qr-area img { width: 260px; max-width: 80%; border-radius: 12px; background: #fff; padding: 10px; }
.btn-danger {
  padding: 12px 22px; border-radius: 10px; border: 1px solid #5a2a2a;
  background: #3a2020; color: #ff9a9a; font-weight: 600; font-size: 15px; cursor: pointer;
}
.btn-danger:hover { border-color: var(--read); }

@media (max-width: 820px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .split { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

.avatar-upload { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.avatar-preview { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: #222; border: 1px solid #333; }
.avatar-upload-actions { display: flex; flex-direction: column; gap: 8px; }
.avatar-upload-actions input[type=file] { font-size: 13px; }

