:root {
  --bg: #f5f6f8; --card: #fff; --text: #14161b; --muted: #636b7a; --line: #e3e6eb; --soft: #eef1f5;
  --brand: #1f6feb; --brand-ink: #fff; --ok: #0f7a55; --warn: #b54708; --err: #c01048;
  --fb: #1877f2; --ig: #c13584; --wa: #128c7e; --out: #1f6feb; --out-ink: #fff; --in: #eef1f5;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1014; --card: #161920; --text: #e7e9ee; --muted: #9aa3b2; --line: #2a2f3a; --soft: #1e222b; --brand: #4c8dff; --in: #232834; --out: #3b74e0; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
a { color: var(--brand); }
h1 { font-size: 24px; margin: 0 0 6px; } h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .pad { padding: 16px; } .lead { max-width: 720px; margin: 0 0 18px; }
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; } .brand span { color: var(--brand); } .brand.big { font-size: 24px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.auth-card h1 { font-size: 20px; margin-top: 18px; }
.auth-foot { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 18px; font-size: 13px; }

/* shell */
.top { display: flex; align-items: center; gap: 18px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.tabs a:hover { background: var(--soft); color: var(--text); }
.tabs a.active { background: var(--soft); color: var(--text); }
.top-right { display: flex; align-items: center; gap: 10px; }
main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 64px; }

/* building blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.danger { border-color: color-mix(in srgb, var(--err) 35%, var(--line)); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; } .row.between { justify-content: space-between; } .row.wrap { flex-wrap: wrap; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.channel { display: flex; flex-direction: column; margin: 0; } .channel p { color: var(--muted); flex: 1; margin: 0 0 14px; }
.icon { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-weight: 700; margin-bottom: 10px; }
.icon.fb { background: var(--fb); } .icon.biz { background: #344054; } .icon.wa { background: var(--wa); }

label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-width: 0; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 0; border-color: var(--brand); }
.conn-select { min-width: 220px; max-width: 100%; }

.btn { appearance: none; border: 0; border-radius: 8px; padding: 9px 14px; font: inherit; font-weight: 600; background: var(--brand); color: var(--brand-ink); cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.06); } .btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, .link:focus-visible, .conv:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 2px; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { background: var(--err); }
.link { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; cursor: pointer; }

.status { min-height: 22px; margin: 0 0 10px; } .status.ok { color: var(--ok); } .status.warn { color: var(--warn); } .status.err { color: var(--err); }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list > li:first-child { border-top: 0; }
.list .name { flex: 1; min-width: 140px; }
.list .empty { display: block; }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; color: #fff; }
.tag.facebook { background: var(--fb); } .tag.instagram { background: var(--ig); } .tag.whatsapp { background: var(--wa); }
.state { font-size: 13px; color: var(--ok); } .state.disconnected { color: var(--err); }

/* inbox */
.inbox { display: grid; grid-template-columns: 300px 1fr; height: min(640px, calc(100vh - 230px)); min-height: 420px; }
.conv-list { border-right: 1px solid var(--line); overflow-y: auto; }
.conv { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 12px 14px; cursor: pointer; color: var(--text); font: inherit; }
.conv:hover { background: var(--soft); } .conv.active { background: color-mix(in srgb, var(--brand) 10%, var(--card)); }
.conv-name { font-weight: 600; } .conv-last { grid-column: 1 / -1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { display: flex; flex-direction: column; min-width: 0; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; min-height: 46px; }
.thread-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { display: flex; flex-direction: column; max-width: 75%; } .msg.in { align-self: flex-start; } .msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 8px 12px; border-radius: 14px; background: var(--in); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.out .bubble { background: var(--out); color: var(--out-ink); }
.meta { margin-top: 2px; } .receipt { align-self: flex-end; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.composer input { flex: 1; }
.composer.small { padding: 8px 0 0; border: 0; width: 100%; }

/* comments, stats */
.comment { display: block !important; } .comment p { margin: 4px 0 8px; } .comment.is-hidden { opacity: .55; }
.stat { margin: 0; } .stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; } .stat.na .stat-value { font-size: 15px; font-weight: 500; color: var(--muted); }

@media (max-width: 760px) {
  .top { gap: 8px; padding: 10px 12px; } .tabs { order: 3; flex-basis: 100%; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .conv-list { max-height: 240px; border-right: 0; border-bottom: 1px solid var(--line); }
  .thread-body { min-height: 300px; } .msg { max-width: 90%; }
  #me-email { display: none; }
}
