/* =========================================================
   Janus — CSS compartilhado (index.html + admin.html)
   ========================================================= */

:root {
  --bg: #0f1620;
  --panel: #1a2538;
  --panel-2: #213049;      /* hover/realce de painel */
  --border: #2a3a52;
  --text: #e8edf5;
  --text-2: #8a9bb5;
  --accent: #00b8d4;
  --accent-hover: #00d4ec;
  --accent-soft: rgba(0, 184, 212, .14);
  --danger: #e05252;
  --danger-soft: rgba(224, 82, 82, .14);
  --success: #3ecf8e;
  --success-soft: rgba(62, 207, 142, .14);
  --warn: #e0b252;

  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 320px;
  --head-h: 64px;
  --t: 150ms ease;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
h1, h2, h3, p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; transition: color var(--t); }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* hidden sempre vence classes com display */
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; flex: none; }

.noscript { padding: 2rem; text-align: center; color: var(--text-2); }

/* ---------- Views ---------- */
.view { height: 100%; }
.view-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

/* ---------- Spinner ---------- */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.spinner-sm { width: 20px; height: 20px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t), border-color var(--t), color var(--t), transform var(--t);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

.btn-primary { background: var(--accent); color: #04212a; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost { border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); border-color: var(--accent); }

.btn-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.btn-success:hover:not(:disabled) { background: var(--success); color: #062016; }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-sm .icon { width: 16px; height: 16px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: 0; border-radius: 50%;
  background: none; color: var(--text-2);
  cursor: pointer;
  transition: background var(--t), color var(--t);
}
.icon-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn-accent { background: var(--accent); color: #04212a; }
.icon-btn-accent:hover:not(:disabled) { background: var(--accent-hover); color: #04212a; }

/* ---------- Formulários ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--text-2); }
.field small { opacity: .8; }

.field input, .field textarea, .field select, .input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--t), box-shadow var(--t);
}
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus, .field textarea:focus, .field select:focus, .input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-error {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

/* ---------- Telas de autenticação ---------- */
.auth-card {
  width: 100%; max-width: 380px;
  padding: 32px 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
  animation: fade-up .25s ease;
}
.auth-logo { height: 48px; width: auto; margin: 0 auto 12px; }
.auth-title { text-align: center; font-size: 22px; font-weight: 600; }
.auth-sub { text-align: center; color: var(--text-2); margin: 4px 0 24px; font-size: 14px; }
.auth-card .form { margin-top: 20px; }
.auth-card .auth-sub + .form { margin-top: 0; }
.auth-text { text-align: center; color: var(--text-2); margin: 16px 0 24px; }
.auth-switch { margin-top: 20px; text-align: center; font-size: 14px; color: var(--text-2); }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* =========================================================
   Chat
   ========================================================= */
.app {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100%;
}

/* Aviso de conexão */
.conn-status {
  position: absolute; top: 8px; left: 50%; z-index: 20;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--warn);
  color: var(--warn);
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}
.conn-status.ok { border-color: var(--success); color: var(--success); }

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.sidebar-head {
  display: flex; align-items: center; gap: 10px;
  height: var(--head-h);
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.sidebar-logo { height: 30px; width: auto; }
.me { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.me-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-admin { font-size: 12px; }
.sidebar-actions { padding: 12px; flex: none; }

.conv-list { flex: 1; overflow-y: auto; padding: 0 6px 12px; }
.conv-empty { padding: 24px 16px; text-align: center; color: var(--text-2); font-size: 14px; }

.conv-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--t);
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--accent-soft); }
.conv-item.active .conv-name { color: var(--accent); }

.avatar {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  font-weight: 600; font-size: 15px;
  text-transform: uppercase;
}
.avatar.group { border-radius: 12px; }

.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: baseline; gap: 8px; }
.conv-name {
  flex: 1; min-width: 0;
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color var(--t);
}
.conv-time { font-size: 12px; color: var(--text-2); flex: none; }
.conv-bottom { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.conv-last {
  flex: 1; min-width: 0;
  font-size: 13px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item.unread .conv-name,
.conv-item.unread .conv-last { color: var(--text); font-weight: 600; }

.badge {
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #04212a;
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
  flex: none;
}

/* Bolinha de presença */
.dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-2);
  opacity: .5;
  flex: none;
}
.dot.online { background: var(--success); opacity: 1; box-shadow: 0 0 0 2px var(--panel); }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; }

/* ---------- Área do chat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.chat-placeholder {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
}

.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-head {
  display: flex; align-items: center; gap: 8px;
  height: var(--head-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex: none;
}
.chat-head-info { min-width: 0; }
.chat-title {
  font-size: 16px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-presence {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
  font-size: 12px; color: var(--text-2);
  white-space: nowrap; overflow: hidden;
}
.presence-item { display: inline-flex; align-items: center; gap: 5px; }

.chat-typing {
  height: 22px;
  padding: 2px 20px 0;
  font-size: 12px; font-style: italic;
  color: var(--accent);
  flex: none;
}

/* ---------- Mensagens ---------- */
.msg-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 20px 12px;
  overscroll-behavior: contain;
}
.msg-loader { display: flex; justify-content: center; padding: 10px; }
.msg-end { text-align: center; font-size: 12px; color: var(--text-2); padding: 10px; }

.msg-list { display: flex; flex-direction: column; gap: 2px; }

.msg-day {
  align-self: center;
  margin: 14px 0 8px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 12px; color: var(--text-2);
}

.msg {
  display: flex; flex-direction: column;
  max-width: min(72%, 640px);
  align-self: flex-start;
  margin-top: 6px;
  animation: msg-in .18s ease;
}
.msg.cont { margin-top: 0; }            /* mesma pessoa em sequência */
.msg.cont .msg-author { display: none; }

.msg-author { font-size: 12px; font-weight: 600; color: var(--accent); margin: 0 0 2px 12px; }

.msg-bubble {
  padding: 8px 12px 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 4px;
}
.msg.cont .msg-bubble { border-top-left-radius: 4px; }

.msg-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.msg-meta {
  display: flex; justify-content: flex-end; align-items: center; gap: 6px;
  margin-top: 2px;
  font-size: 11px; color: var(--text-2);
}

/* Minhas mensagens */
.msg.mine { align-self: flex-end; }
.msg.mine .msg-author { display: none; }
.msg.mine .msg-bubble {
  background: var(--accent-soft);
  border-color: rgba(0, 184, 212, .35);
  border-radius: 14px 14px 4px 14px;
}
.msg.mine.cont .msg-bubble { border-top-right-radius: 4px; }

/* Estados de envio */
.msg-status::before { content: "✓"; }
.msg.sending .msg-bubble { opacity: .6; }
.msg.sending .msg-status::before { content: "…"; }
.msg.failed .msg-bubble { border-color: var(--danger); background: var(--danger-soft); }
.msg.failed .msg-status { color: var(--danger); }
.msg.failed .msg-status::before { content: "!"; font-weight: 700; }
.msg-error { margin: 3px 4px 0 0; font-size: 12px; color: var(--danger); text-align: right; }

@keyframes msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Composer ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--panel);
  flex: none;
}
.composer-input {
  flex: 1;
  min-height: 40px; max-height: 160px;
  padding: 9px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  resize: none;
  line-height: 1.4;
  transition: border-color var(--t), box-shadow var(--t);
}
.composer-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer .icon-btn { width: 40px; height: 40px; }

/* ---------- Diálogo ---------- */
.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 24px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.dialog::backdrop { background: rgba(5, 10, 16, .65); }
.dialog[open] { animation: fade-up .2s ease; }
.dialog-title { font-size: 18px; font-weight: 600; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ---------- Scrollbar ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Mobile (< 768px): uma coluna por vez ---------- */
.only-mobile { display: none; }

@media (max-width: 767.98px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-flex; }
  .sidebar { border-right: 0; }
  .chat { display: none; }
  /* app.js adiciona .show-chat ao abrir uma conversa */
  .app.show-chat .sidebar { display: none; }
  .app.show-chat .chat { display: flex; }
  .msg { max-width: 85%; }
  .msg-scroll { padding: 4px 12px 12px; }
  .chat-head { padding: 0 8px; }
}

/* =========================================================
   Admin
   ========================================================= */
.admin { height: 100%; overflow-y: auto; }

.admin-head {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  height: var(--head-h);
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.admin-head h1 { font-size: 18px; font-weight: 600; flex: 1; }

.admin-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex; flex-direction: column; gap: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-bottom: 16px;
}
.card-head h2 { font-size: 16px; font-weight: 600; flex: 1; }

.filter { display: inline-flex; gap: 4px; padding: 3px; background: var(--bg); border-radius: var(--radius-sm); }
.filter button {
  padding: 5px 12px;
  border: 0; border-radius: 4px;
  background: none; color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--t), color var(--t);
}
.filter button:hover { color: var(--text); }
.filter button.active { background: var(--panel-2); color: var(--accent); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.table tbody tr { transition: background var(--t); }
.table tbody tr:hover { background: var(--panel-2); }
.table td.actions { text-align: right; }
.table td.actions .btn + .btn { margin-left: 6px; }
.table-empty { padding: 24px; text-align: center; color: var(--text-2); }

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.pill-pending { background: rgba(224, 178, 82, .15); color: var(--warn); }
.pill-active  { background: var(--success-soft); color: var(--success); }
.pill-blocked { background: var(--danger-soft); color: var(--danger); }

.domain-form { display: flex; gap: 10px; margin-bottom: 14px; }
.domain-form .input { flex: 1; max-width: 360px; }
.domain-list { display: flex; flex-direction: column; }
.domain-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
}
.domain-list li:last-child { border-bottom: 0; }

/* Toast de feedback (admin e chat) */
.toast {
  position: fixed; bottom: 20px; left: 50%; z-index: 50;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  font-size: 14px;
  animation: fade-up .2s ease;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.ok { border-color: var(--success); color: var(--success); }

@media (max-width: 767.98px) {
  .admin-main { padding: 16px 12px 40px; }
  .card { padding: 16px; }
  .domain-form .input { max-width: none; }
}

/* ---------- Acessibilidade: menos movimento ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
