:root {
  --primary: #b3121f;
  --primary-dark: #7a0c15;
  --primary-light: #e8dad9;
  --ink: #111111;
  --ink-soft: #3a3a3a;
  --paper: #ffffff;
  --bg: #f4f1ef;
  --bg-chat: #efe7e4;
  --border: #e2dcda;
  --muted: #767676;
  --bubble-in: #ffffff;
  --bubble-out: #f6d9d9;
  --bubble-out-border: #e9b9ba;
  --success: #1f9d55;
  --danger: #c0392b;
  --warning: #b8860b;
  --radius: 10px;
  --rail-width: 76px;
  --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;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* ---------- Rail lateral (navegação principal) ---------- */
.rail {
  width: var(--rail-width);
  background: linear-gradient(180deg, var(--ink) 0%, #1c1c1c 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  flex-shrink: 0;
  transition: width .18s ease;
  position: relative;
  z-index: 30;
}

.rail.expanded {
  width: 216px;
  align-items: stretch;
}

.rail-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 0 14px;
  margin-bottom: 22px;
}

.rail.expanded .rail-top { justify-content: space-between; }

.rail-toggle {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #cfcfcf;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.rail-toggle:hover { background: rgba(255,255,255,0.18); color: #fff; }

.rail-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  width: 100%;
  align-items: center;
  padding: 0 12px;
}

.rail.expanded .rail-nav { align-items: stretch; }

.rail-item {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #cfcfcf;
  font-size: 21px;
  transition: background .15s ease, color .15s ease;
  gap: 12px;
  flex-shrink: 0;
}

.rail.expanded .rail-item {
  width: 100%;
  justify-content: flex-start;
  padding: 0 14px;
}

.rail-label {
  display: none;
  white-space: nowrap;
  font-size: 13.5px;
  font-weight: 600;
}

.rail.expanded .rail-label { display: inline; }

.rail-item:hover { background: rgba(255,255,255,0.08); color: #fff; }

.rail-item.active {
  background: var(--primary);
  color: #fff;
}

.rail-item .badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ink);
}

.rail-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.rail-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary-dark);
  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.15);
}

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

/* ---------- Conteúdo principal ---------- */
.main-content {
  flex: 1;
  display: flex;
  min-width: 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; }

.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; }

.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;
}

.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); }

.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(--ink) 0%, var(--primary-dark) 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-card .rail-logo { margin: 0 auto 18px; }
.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;
  bottom: 0;
  left: 62px;
  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;
  bottom: 0;
  left: 62px;
  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 {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.notif-item.unread { background: var(--primary-light); }

/* ---------- 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%;
  aspect-ratio: 1 / 1;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.post-media img, .post-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.post-media.is-audio { aspect-ratio: auto; background: var(--bg); padding: 20px 16px; }
.post-media.is-audio audio { width: 100%; }

.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 matrix ---------- */
.perm-matrix { overflow-x: auto; }
.perm-matrix table { min-width: 760px; }
.perm-matrix td.checks { white-space: nowrap; }
.perm-matrix td.checks .checks-row { display: flex; gap: 12px; }
.perm-matrix label { display: flex; align-items: center; gap: 4px; font-size: 12px; }

/* ---------- 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; }
}
