/* ── WhatsHUB — design sóbrio e profissional ──────────── */
:root {
  --bg: #f5f6f7;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-dark: #0b5e58;
  --accent-soft: #e6f2f0;
  --danger: #b42318;
  --danger-soft: #fdf1f0;
  --text: #1a212b;
  --text-dim: #6a7280;
  --border: #e3e6ea;
  --border-strong: #d3d8de;
  --bubble-in: #ffffff;
  --bubble-out: #dcf0ea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; margin-bottom: 14px; font-weight: 500; font-size: 13px; }
label input, label select, label textarea { margin-top: 6px; font-weight: 400; }
label small { display: block; margin-top: 4px; color: var(--text-dim); font-weight: 400; }

.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-sm { width: 15px; height: 15px; }
.icon-xl { width: 46px; height: 46px; stroke-width: 1.1; opacity: .3; }

.btn {
  border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 8px 14px; font-weight: 600;
  background: #fff; color: var(--text); transition: background .12s, border-color .12s;
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  box-shadow: var(--shadow);
}
.btn:hover { background: #f7f8f9; border-color: #c3c9d0; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { background: #fff; border-color: #e8c5c1; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ai { background: #fff; border-color: var(--accent); color: var(--accent); }
.btn-ai:hover { background: var(--accent-soft); }
.btn-ai-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--accent); }
.btn-ai-ghost:hover { background: var(--accent-soft); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  border: none; background: transparent; padding: 7px; border-radius: var(--radius);
  color: var(--text-dim); display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: #eef0f2; color: var(--text); }
.icon-btn-dark:hover { background: #eef0f2; color: var(--text); }
.row-gap { display: flex; gap: 8px; }

/* ── Login ────────────────────────────────────────────── */
.auth-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: #eef0f2;
}
.auth-card {
  width: 380px; max-width: calc(100vw - 32px);
  background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 36px 32px 24px;
  box-shadow: 0 4px 24px rgba(16, 24, 40, .08);
}
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-logo {
  width: 54px; height: 54px; margin: 0 auto 12px; border-radius: 12px;
  background: var(--accent); color: #fff; font-size: 28px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.auth-brand h1 { font-size: 23px; letter-spacing: -0.4px; }
.auth-tagline { color: var(--text-dim); font-size: 13px; margin-top: 4px; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; text-align: center; }
.auth-footer { text-align: center; color: var(--text-dim); font-size: 12.5px; margin-top: 14px; }

/* ── Layout ───────────────────────────────────────────── */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 228px; flex-shrink: 0; background: var(--panel); color: var(--text);
  display: flex; flex-direction: column; padding: 16px 12px;
  border-right: 1px solid var(--border);
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent);
  color: #fff; font-weight: 800; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-weight: 700; font-size: 16px; color: var(--text); letter-spacing: -0.2px; }
.brand-sub { font-size: 11px; color: var(--text-dim); margin-top: 1px; }

.conn-pill {
  display: flex; align-items: center; gap: 8px; margin: 0 4px 16px;
  background: #f2f4f5; border-radius: 999px; padding: 7px 13px; font-size: 12.5px; color: var(--text-dim);
}
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa2ad; flex-shrink: 0; }
.conn-dot.open { background: #12b76a; }
.conn-dot.connecting { background: #f0a92e; }
.conn-dot.close { background: #d92d20; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  text-align: left; border: none; background: transparent; color: var(--text-dim);
  padding: 9px 12px; border-radius: var(--radius); font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 11px;
}
.nav-item:hover { background: #f2f4f5; color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 4px; }
.user-row { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--text-dim); padding: 0 6px; }

.main { flex: 1; min-width: 0; display: flex; background: var(--bg); }
.view { flex: 1; min-width: 0; display: flex; }

/* ── Conversas ───────────────────────────────────────── */
.chats-layout { display: flex; flex: 1; min-width: 0; }
.chat-list-pane {
  width: 330px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.pane-header { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.pane-header input { flex: 1; }
.chat-list { flex: 1; overflow-y: auto; }

.chat-item {
  display: flex; gap: 11px; padding: 11px 14px; cursor: pointer; align-items: center;
  border-bottom: 1px solid #f2f4f5;
}
.chat-item:hover { background: #f7f8f9; }
.chat-item.active { background: var(--accent-soft); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; background: #dde1e6; color: #4b5563;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px;
  flex-shrink: 0; overflow: hidden; background-size: cover; background-position: center;
}
.chat-item-main { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; gap: 8px; }
.chat-item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 11.5px; color: var(--text-dim); flex-shrink: 0; }
.chat-item-bottom { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; align-items: center; }
.chat-item-preview { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badges { display: flex; gap: 5px; align-items: center; flex-shrink: 0; }
.badge-unread {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 999px; min-width: 19px; height: 19px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
}
.chip {
  font-size: 10px; font-weight: 700; letter-spacing: .04em; border-radius: 4px; padding: 2px 6px;
  text-transform: uppercase;
}
.chip-ai { background: var(--accent-soft); color: var(--accent-dark); border: 1px solid #c8e2dd; }
.chip-muted { background: #eef0f2; color: var(--text-dim); }

.chat-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: #eef0f1; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-dim); text-align: center; gap: 14px;
}
.chat-open { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.chat-header {
  background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; padding: 9px 16px;
}
.chat-header-info { display: flex; gap: 11px; align-items: center; }
.chat-title { font-weight: 700; }
.chat-subtitle { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.chat-header-actions { display: flex; gap: 8px; align-items: center; }

.messages { flex: 1; overflow-y: auto; padding: 18px 7%; display: flex; flex-direction: column; gap: 5px; }
.msg { max-width: 66%; padding: 8px 12px; border-radius: 10px; box-shadow: var(--shadow); position: relative; background: var(--bubble-in); }
.msg-in { align-self: flex-start; border-bottom-left-radius: 3px; }
.msg-out { background: var(--bubble-out); align-self: flex-end; border-bottom-right-radius: 3px; }
.msg-sender { font-size: 12px; font-weight: 700; color: var(--accent-dark); margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; word-wrap: break-word; }
.msg-media-label { font-size: 12.5px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.msg-time { font-size: 10.5px; color: #8b929c; text-align: right; margin-top: 3px; }
.msg-img { max-width: 280px; max-height: 320px; border-radius: 7px; display: block; cursor: zoom-in; }
.msg-video { max-width: 300px; border-radius: 7px; display: block; }
.msg-audio { width: 260px; display: block; }
.msg-doc {
  display: inline-flex; align-items: center; gap: 8px; color: var(--text);
  background: #f2f4f5; border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 12px; text-decoration: none; font-weight: 500;
}
.msg-doc:hover { background: #eaedee; }
.msg-caption { margin-top: 6px; }
.day-sep {
  align-self: center; background: #fff; color: var(--text-dim); font-size: 12px;
  border: 1px solid var(--border); border-radius: 6px; padding: 3px 12px; margin: 8px 0;
}

.ai-result {
  background: #fbfbfa; border-top: 1px solid var(--border); border-left: 3px solid var(--accent);
  max-height: 42%; display: flex; flex-direction: column;
}
.ai-result-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px 0; }
.ai-result-title { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: 13px; color: var(--accent-dark); }
.ai-result-body { overflow-y: auto; padding: 10px 16px 14px; white-space: pre-wrap; font-size: 13.5px; line-height: 1.6; }

.composer { background: var(--panel); border-top: 1px solid var(--border); padding: 8px 14px 10px; }
.composer-tools { display: flex; gap: 14px; align-items: center; margin-bottom: 6px; }
.toggle-sm { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-dim); margin: 0; font-weight: 500; }
.toggle-sm input { width: auto; margin: 0; accent-color: var(--accent); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-row textarea { resize: none; max-height: 140px; }
.composer-btn { height: 37px; flex-shrink: 0; }
.composer-note { font-size: 12px; color: var(--text-dim); min-height: 16px; margin-top: 4px; }
.composer-note.warn { color: #b54708; }
.composer-note.ai { color: var(--accent-dark); }

/* ── Páginas ─────────────────────────────────────────── */
.page { flex: 1; overflow-y: auto; padding: 26px 34px; }
.page-narrow { max-width: 660px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.page-head h2 { font-size: 20px; letter-spacing: -0.3px; }
.page-head-actions { display: flex; gap: 14px; align-items: center; }
.page-hint { color: var(--text-dim); font-size: 13px; margin-bottom: 18px; }
.hint-block { color: var(--text-dim); font-size: 13px; margin-top: 12px; line-height: 1.5; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-dim); margin: 24px 0 10px; font-weight: 700; }

.settings-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.toggle { display: flex; align-items: center; gap: 9px; font-weight: 500; margin-bottom: 10px; }
.toggle input { width: auto; margin: 0; accent-color: var(--accent); }
.save-ok { color: var(--accent-dark); font-weight: 600; margin-left: 10px; }

.conn-status-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.qr-box { text-align: center; margin-top: 16px; }
.qr-box img { width: 240px; height: 240px; border: 1px solid var(--border); border-radius: 10px; }
.qr-box p { color: var(--text-dim); font-size: 13px; margin-top: 8px; }

.rules-list { display: flex; flex-direction: column; gap: 10px; }
.rule-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; display: flex; justify-content: space-between; gap: 14px; align-items: center;
  box-shadow: var(--shadow);
}
.rule-card.disabled { opacity: .55; }
.rule-info { min-width: 0; }
.rule-name { font-weight: 700; }
.rule-desc { font-size: 13px; color: var(--text-dim); margin-top: 3px; }
.rule-tags { display: flex; gap: 6px; margin-top: 7px; flex-wrap: wrap; }
.tag { background: #eef0f2; border-radius: 999px; font-size: 11.5px; padding: 3px 9px; color: var(--text-dim); }
.tag.ai { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.rule-actions { display: flex; gap: 6px; flex-shrink: 0; }

.cards-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 18px; min-width: 160px; box-shadow: var(--shadow);
}
.stat-card .num { font-size: 22px; font-weight: 800; }
.stat-card .lbl { font-size: 12.5px; color: var(--text-dim); }

.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--text-dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.table td { padding: 9px 14px; border-bottom: 1px solid #f2f4f5; vertical-align: top; }
.status-ok { color: var(--accent-dark); font-weight: 600; }
.status-fail { color: var(--danger); font-weight: 600; }
.status-pending { color: #b54708; font-weight: 600; }
.status-muted { color: var(--text-dim); }

/* ── Drawer / modais ─────────────────────────────────── */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(26, 33, 43, .45); z-index: 40;
  display: flex; justify-content: flex-end;
}
.drawer {
  width: 390px; max-width: 92vw; background: #fff; height: 100%; padding: 22px;
  overflow-y: auto; border-left: 1px solid var(--border); box-shadow: -6px 0 24px rgba(16, 24, 40, .12);
}
.drawer-wide { width: 580px; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.drawer-head h3 { font-size: 16.5px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1a212b; color: #fff; padding: 10px 20px; border-radius: var(--radius);
  font-size: 13.5px; z-index: 60; box-shadow: 0 6px 20px rgba(16, 24, 40, .3);
}
.toast.error { background: var(--danger); }

.img-lightbox {
  position: fixed; inset: 0; background: rgba(26, 33, 43, .88); z-index: 70;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.img-lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

/* secretária + recibos de leitura */
.btn-secretary-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-secretary-on:hover { background: var(--accent-dark); }
.receipt { display: inline-flex; vertical-align: middle; color: #8b929c; }
.receipt .icon { width: 14px; height: 14px; }
.receipt.read { color: #2f80ed; }

@media (max-width: 900px) {
  .sidebar { width: 64px; padding: 14px 6px; }
  .brand-name, .brand-sub, .conn-pill span:last-child, .user-row span, .nav-item span, .sidebar-footer .btn span { display: none; }
  .nav-item { justify-content: center; padding: 10px 4px; }
  .chat-list-pane { width: 250px; }
}

/* arquivadas toggle ativo */
.icon-btn.active { background: var(--accent-soft); color: var(--accent-dark); }
