/* Buy or Block — Messaging & unified inbox (uses tokens from app.css) */
:root { --wa: #25D366; --wa-bubble: #DCF8C6; --sms: #155EEF; --mail: #7A5AF8; }

/* ---------- 3-pane inbox ---------- */
.page-inbox .content { max-width: none; padding: 0; }
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; height: calc(100vh - var(--topbar-h)); background: var(--surface); }
.inbox-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.inbox-list-head { padding: 16px 16px 8px; border-bottom: 1px solid var(--border); }
.inbox-views { display: flex; gap: 4px; margin: 12px 0 10px; background: var(--gray-100); padding: 3px; border-radius: var(--radius); }
.inbox-view { flex: 1; text-align: center; padding: 6px 8px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.inbox-view.active { background: #fff; color: var(--text); box-shadow: var(--shadow-xs); }
.inbox-count { background: var(--primary-50); color: var(--primary-700); border-radius: 999px; padding: 0 7px; font-size: 11px; line-height: 18px; }
.inbox-filters { display: flex; flex-direction: column; gap: 8px; }
.inbox-search { position: relative; }
.inbox-search i, .inbox-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted-2); }
.inbox-search input { width: 100%; padding: 8px 10px 8px 32px; border: 1px solid var(--border-strong); border-radius: var(--radius); font: inherit; font-size: 13px; }
.inbox-search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-100); }
.select-sm { padding: 6px 10px; font-size: 13px; flex: 1; min-width: 0; border: 1px solid var(--border-strong); border-radius: var(--radius); background: #fff; font-family: inherit; }
.inbox-items { overflow-y: auto; flex: 1; }
.inbox-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); position: relative; }
.inbox-item:hover { background: var(--surface-2); color: var(--text); }
.inbox-item.active { background: var(--primary-50); }
.inbox-item.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary); }
.inbox-item .avatar { position: relative; overflow: visible; }
.inbox-ch { position: absolute; right: -4px; bottom: -4px; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; color: #fff; border: 2px solid #fff; }
.inbox-ch [data-lucide], .inbox-ch svg { width: 10px; height: 10px; }
.ch-whatsapp.inbox-ch, .tpl-ch.ch-whatsapp { background: var(--wa); }
.ch-sms.inbox-ch, .tpl-ch.ch-sms { background: var(--sms); }
.ch-email.inbox-ch, .tpl-ch.ch-email { background: var(--mail); }
.inbox-item-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.inbox-name { font-weight: 500; flex: 1; min-width: 0; }
.inbox-item.unread .inbox-name, .inbox-item.unread .inbox-preview { font-weight: 700; color: var(--text); }
.inbox-time { font-size: 11px; color: var(--muted-2); white-space: nowrap; }
.inbox-preview { font-size: 13px; color: var(--muted); flex: 1; min-width: 0; }
.inbox-unread { margin-left: auto; background: var(--primary); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; line-height: 18px; font-weight: 700; }
.inbox-tags { display: flex; gap: 6px; align-items: center; margin-top: 2px; }
.inbox-tags .badge { padding: 0 8px; font-size: 11px; line-height: 18px; }

.inbox-thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.thread-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.thread-actions .select-sm { min-width: 150px; }
.thread-empty { margin: auto; }
.thread-alert { margin: 0 20px 8px; }
.wa-window { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.wa-window.open { background: var(--green-50); color: var(--green-700); }
.wa-window.closed { background: var(--amber-50); color: var(--amber-700); }

/* ---------- bubbles ---------- */
.msg-thread { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 6px; }
.msg-thread.mini { max-height: 340px; padding: 4px 2px 12px; background: none; }
.msg-day { text-align: center; margin: 10px 0; }
.msg-day span { font-size: 11px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; }
.msg-row { display: flex; flex-direction: column; align-items: flex-start; max-width: 100%; }
.msg-row.out { align-items: flex-end; }
.msg-bubble { max-width: min(560px, 82%); padding: 8px 12px 6px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-xs); border-bottom-left-radius: 4px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-row.out .msg-bubble { background: var(--primary); border-color: var(--primary); color: #fff; border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
.msg-row.out .msg-bubble.ch-whatsapp { background: var(--wa-bubble); border-color: #bfe9a6; color: var(--text); }
.msg-row.out .msg-bubble.ch-email { background: var(--purple-50); border-color: #d9d6fe; color: var(--text); }
.msg-row.out .msg-bubble.is-failed { background: var(--red-50); border-color: #FECDCA; color: var(--red-700); }
.msg-row.out .msg-bubble.is-queued { opacity: .8; border-style: dashed; }
.msg-subject { font-weight: 700; margin-bottom: 2px; }
.msg-text { white-space: normal; line-height: 1.45; }
.msg-meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 11px; opacity: .75; margin-top: 2px; }
.msg-meta [data-lucide], .msg-meta svg { width: 13px; height: 13px; }
.msg-tick.st-read, .msg-row.out .ch-whatsapp .msg-tick.st-read { color: #53BDEB; opacity: 1; }
.msg-row.out .msg-bubble:not(.ch-whatsapp):not(.ch-email) .msg-tick.st-read { color: #B2DDFF; }
.msg-tick.st-failed { color: var(--red-700); }
.msg-note { font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; margin-top: 2px; }
.msg-note.error { color: var(--red-700); }
.msg-note.subtle { color: var(--muted-2); }

/* ---------- composer ---------- */
.msg-composer { background: var(--surface); border-top: 1px solid var(--border); padding: 12px 20px 14px; }
.msg-composer.compact { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 10px 12px; }
.msg-composer-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.msg-channels { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.msg-channel { margin: 0; }
.msg-channel input { display: none; }
.msg-channel span { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; border-right: 1px solid var(--border); }
.msg-channel:last-child span { border-right: 0; }
.msg-channel input:checked + span { background: var(--primary-50); color: var(--primary-700); }
.msg-channel.is-disabled span { opacity: .45; cursor: not-allowed; }
.msg-composer-tools { display: flex; gap: 6px; margin-left: auto; align-items: center; }
.msg-template-select { padding: 6px 10px; font-size: 13px; max-width: 220px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: #fff; font-family: inherit; }
.msg-composer .dropdown-menu code { font-size: 12px; }
.msg-body { width: 100%; min-height: 72px !important; resize: vertical; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); font: inherit; }
.msg-body:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-100); }
.msg-body[readonly] { background: var(--surface-2); color: var(--text-2); }
.msg-composer-foot { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.msg-composer-foot .btn { margin-left: auto; }
.msg-counter { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.msg-window { font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: var(--radius); margin-bottom: 8px; }
.msg-window.open { background: var(--green-50); color: var(--green-700); }
.msg-window.closed { background: var(--amber-50); color: var(--amber-700); }
.btn.is-loading { opacity: .7; pointer-events: none; }

/* ---------- right contact pane ---------- */
.inbox-contact { border-left: 1px solid var(--border); padding: 20px; overflow-y: auto; background: var(--surface); }
.inbox-contact .avatar-lg { margin: 0 auto; }
.inbox-contact .kv { grid-template-columns: 100px 1fr; }
.inbox-other { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius); color: var(--text-2); font-weight: 500; }
.inbox-other:hover { background: var(--surface-2); }

/* ---------- contact panel ---------- */
.msg-panel { margin-top: 16px; }
.msg-panel .card-header h3 { display: flex; align-items: center; gap: 8px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }

/* ---------- templates page ---------- */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.tpl-card { display: flex; flex-direction: column; }
.tpl-card .card-body { flex: 1; }
.tpl-card.is-inactive { opacity: .6; }
.tpl-ch { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; color: #fff; flex-shrink: 0; }
.tpl-body { font-size: 13px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; max-height: 140px; overflow: auto; }
.var-chip { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--primary-50); color: var(--primary-700); }
.hook-url { display: flex; gap: 8px; }
.hook-url .input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.wrap { flex-wrap: wrap; }

@media (max-width: 1200px) {
  .inbox { grid-template-columns: 300px minmax(0, 1fr); }
  .inbox-contact { display: none; }
}
@media (max-width: 860px) {
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox-list { max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .inbox-thread { min-height: 70vh; }
  .msg-composer-tools { margin-left: 0; width: 100%; }
  .msg-template-select { max-width: none; flex: 1; }
  .hide-sm { display: none; }
}
