:root {color-scheme:light;font:15px/1.45 "Segoe UI",sans-serif;color:#17334a;background:#edf3f8;--blue:#006aad;--border:#dbe5ee}
* {box-sizing:border-box}
body {margin:0;min-width:300px;height:100dvh;display:flex;flex-direction:column}
h1,h2,p {margin:0}
h1 {font-size:26px}
h2 {font-size:19px;overflow-wrap:anywhere}
small {color:#58738b;letter-spacing:.08em;font-weight:650}
.topbar,.thread-header {display:flex;align-items:center;justify-content:space-between;gap:14px;padding:16px 24px;background:white;border-bottom:1px solid var(--border)}
main {flex:1;min-height:0;display:grid;grid-template-columns:minmax(280px,360px) minmax(0,1fr);max-width:1500px;width:100%;margin:auto;background:white}
.sidebar,.thread {display:flex;flex-direction:column;min-height:0}
.sidebar {border-right:1px solid var(--border)}
.filters {display:grid;gap:9px;padding:14px}
.filters label {font-size:13px}
button,input,select,a {font:inherit}
button,select,input[type=search],#crm-link {padding:8px 12px;border:1px solid #b9ccdb;border-radius:8px;background:#fff;color:#17334a}
button {cursor:pointer}
button:disabled {opacity:.6;cursor:wait}
#crm-link {color:var(--blue);text-decoration:none;flex-shrink:0}
#status,#link-status {font-size:12px;color:#536c81}
#status {padding:2px 14px 12px}
#chats,#messages {overflow:auto;flex:1}
.chat {width:100%;display:grid;grid-template-columns:minmax(0,1fr) auto;gap:3px 9px;text-align:left;border:0;border-top:1px solid var(--border);border-radius:0;padding:12px 14px;background:white}
.chat:hover,.chat[aria-current=true] {background:#e9f5ff}
.chat strong,.preview {overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.preview,.meta {font-size:12px;color:#526c82}
.count {background:#0076be;color:white;min-width:22px;text-align:center;padding:1px 5px;border-radius:12px;font-size:12px;justify-self:end}
#messages {background:var(--chat-bg,#f2f4f6);padding:16px clamp(14px,4vw,44px)}
.message {width:fit-content;max-width:82%;margin:0 0 11px;padding:9px 13px;border-radius:12px;background:white;white-space:pre-wrap;overflow-wrap:anywhere}
.message.outgoing {margin-left:auto;background:var(--chat-out,#d2edff)}
.thread[data-channel="telegram"] {--chat-bg:#edf5fa}
.thread[data-channel="whatsapp"] {--chat-bg:#e3f1e7;--chat-out:#c9ebd2}
.thread[data-channel="max"] {--chat-bg:#261e3e;--chat-out:#e4d8ff}
.thread[data-channel="whatsapp"] #thread-channel {color:#18633d}
.thread[data-channel="max"] #thread-channel {color:#503184}
.thread[data-channel="max"] #messages .empty {color:#f3edff}
.message time {display:block;text-align:right;color:#536c81;font-size:11px;margin-top:3px}
.empty {padding:20px;text-align:center;color:#536c81}
.access-form {display:grid;gap:12px;width:min(420px,calc(100% - 32px));margin:48px auto;padding:24px;border:1px solid var(--border);border-radius:14px;background:white}
.access-form input {padding:9px 12px;border:1px solid #b9ccdb;border-radius:8px}
#access-status {color:#536c81}
footer {padding:11px 24px;border-top:1px solid var(--border);font-size:12px;color:#536c81}
#compose:not([hidden]) {display:flex;align-items:center;gap:10px}
#draft {flex:1;min-width:0;font:inherit;padding:8px;resize:vertical}
#send-status:not(:empty) {margin-top:6px}
[hidden] {display:none!important}
@media(max-width:690px){
 main {grid-template-columns:1fr}
 .thread {display:none}
 main.thread-open .sidebar {display:none}
 main.thread-open .thread {display:flex}
 .thread-header,.topbar {padding:12px}
 .thread-header {flex-wrap:wrap}
}
