.cim-chat-portal{--chat-border:#e3e8ee;--chat-ink:#17212b;--chat-muted:#687584;min-height:660px;background:#fff;border:1px solid var(--chat-border);border-radius:20px;overflow:hidden;box-shadow:0 16px 45px rgba(22,38,55,.07);font-family:inherit;color:var(--chat-ink)}
.cim-chat-shell{display:grid;grid-template-columns:340px minmax(0,1fr);height:700px;max-height:calc(100vh - 130px)}
.cim-chat-sidebar{display:flex;flex-direction:column;min-width:0;border-right:1px solid var(--chat-border);background:#f8fafc}.cim-chat-sidebar header{display:flex;justify-content:space-between;align-items:center;padding:20px;border-bottom:1px solid var(--chat-border)}.cim-chat-sidebar header span{font-size:12px;color:var(--chat-muted);text-transform:uppercase;letter-spacing:.08em}.cim-chat-sidebar h1{font-size:24px;margin:3px 0 0}.cim-chat-sidebar header button{width:38px;height:38px;border:0;border-radius:11px;background:#17212b;color:#fff;font-size:25px;cursor:pointer}.cim-chat-sidebar__tools{display:flex;gap:6px;padding:10px 14px;flex-wrap:wrap;border-bottom:1px solid var(--chat-border)}.cim-chat-sidebar__tools button{border:1px solid #d9e1e9;background:#fff;border-radius:999px;padding:6px 9px;font-size:11px;cursor:pointer}.cim-chat-list{overflow:auto;flex:1}.cim-chat-list-empty{padding:30px 20px;text-align:center;color:var(--chat-muted);line-height:1.6}.cim-chat-sidebar footer{padding:10px 16px;border-top:1px solid var(--chat-border);font-size:12px;color:var(--chat-muted)}
.cim-chat-list-item{width:100%;display:grid;grid-template-columns:40px minmax(0,1fr) auto;gap:10px;align-items:center;text-align:left;border:0;border-bottom:1px solid #edf1f5;background:transparent;padding:14px;cursor:pointer}.cim-chat-list-item:hover,.cim-chat-list-item.is-active{background:#fff}.cim-chat-channel{display:grid;place-items:center;width:38px;height:38px;border-radius:12px;background:#e9eef3;font-size:10px;font-weight:800}.cim-chat-channel.is-telegram{background:#dff2ff;color:#1677a9}.cim-chat-channel.is-max{background:#eae7ff;color:#5a43b6}.cim-chat-list-item__body{min-width:0}.cim-chat-list-item__body strong,.cim-chat-list-item__body small{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.cim-chat-list-item__body strong{font-size:14px}.cim-chat-list-item__body small{margin-top:4px;color:var(--chat-muted);font-size:12px}.cim-chat-list-item__meta{text-align:right}.cim-chat-list-item__meta time{display:block;font-size:10px;color:#8a95a1}.cim-chat-list-item__meta b{display:inline-grid;place-items:center;min-width:20px;height:20px;margin-top:6px;padding:0 5px;border-radius:999px;background:#dc3e3e;color:#fff;font-size:11px}
.cim-chat-main{display:flex;flex-direction:column;min-width:0;background:#fff}.cim-chat-head{display:flex;gap:12px;align-items:center;padding:18px 24px;border-bottom:1px solid var(--chat-border);min-height:74px}.cim-chat-head span,.cim-chat-head small{display:block;color:var(--chat-muted);font-size:12px}.cim-chat-head h2{font-size:20px;margin:3px 0}.cim-chat-back{display:none;border:0;background:transparent;font-size:20px}.cim-chat-messages{flex:1;overflow:auto;padding:24px;background:linear-gradient(180deg,#fbfcfd,#f5f7f9)}.cim-chat-message{display:flex;margin:10px 0}.cim-chat-message.is-own{justify-content:flex-end}.cim-chat-bubble{max-width:min(680px,82%);padding:12px 14px;border-radius:16px 16px 16px 4px;background:#fff;border:1px solid #e5e9ed;box-shadow:0 4px 14px rgba(23,33,43,.04)}.cim-chat-message.is-own .cim-chat-bubble{background:#e9f3ff;border-color:#d2e7fb;border-radius:16px 16px 4px 16px}.cim-chat-bubble header{display:flex;gap:18px;justify-content:space-between;margin-bottom:6px}.cim-chat-bubble header strong{font-size:12px}.cim-chat-bubble time{font-size:10px;color:#8b96a1}.cim-chat-bubble p{margin:0;line-height:1.5;font-size:14px}.cim-chat-file{display:grid;grid-template-columns:28px minmax(0,1fr) auto;align-items:center;gap:7px;margin-top:8px;padding:9px;border-radius:10px;background:rgba(255,255,255,.7);color:inherit;text-decoration:none}.cim-chat-file b{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:12px}.cim-chat-file small{font-size:10px;color:var(--chat-muted)}.cim-chat-bubble .is-error{display:block;color:#ba2929;margin-top:7px}
.cim-chat-composer{display:grid;grid-template-columns:42px minmax(0,1fr) auto;align-items:end;gap:10px;padding:15px 18px;border-top:1px solid var(--chat-border);background:#fff}.cim-chat-composer textarea{width:100%;min-height:44px;max-height:140px;resize:vertical;border:1px solid #dce2e8;border-radius:13px;padding:11px 13px;font:inherit}.cim-chat-composer button{height:44px;border:0;border-radius:12px;background:#17212b;color:#fff;padding:0 20px;font-weight:700;cursor:pointer}.cim-chat-attach{display:grid;place-items:center;height:42px;border-radius:11px;background:#eef2f5;cursor:pointer}.cim-chat-attach input{display:none}.cim-chat-selected-files{grid-column:2/4;color:var(--chat-muted);font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.cim-chat-closed{display:flex;justify-content:center;gap:12px;align-items:center;padding:16px;border-top:1px solid var(--chat-border);background:#f7f9fb}.cim-chat-closed button,.cim-chat-welcome button{border:0;border-radius:11px;background:#17212b;color:#fff;padding:10px 16px;cursor:pointer}.cim-chat-welcome{margin:auto;max-width:500px;text-align:center;padding:35px}.cim-chat-welcome>div{font-size:50px}.cim-chat-welcome h2{font-size:26px}.cim-chat-welcome p{color:var(--chat-muted);line-height:1.6}.cim-chat-loading,.cim-chat-error{padding:50px;text-align:center}.cim-chat-floating{position:fixed;right:24px;bottom:24px;z-index:999;display:flex;align-items:center;gap:8px;padding:12px 16px;border-radius:999px;background:#17212b;color:#fff!important;text-decoration:none!important;box-shadow:0 12px 35px rgba(0,0,0,.2)}
.cim-chat-modal{position:fixed;inset:0;z-index:100000;display:grid;place-items:center;padding:20px}.cim-chat-modal>div{position:absolute;inset:0;background:rgba(12,20,28,.55)}.cim-chat-modal form{position:relative;width:min(560px,100%);background:#fff;border-radius:18px;box-shadow:0 30px 80px rgba(0,0,0,.25);overflow:hidden}.cim-chat-modal header,.cim-chat-modal footer{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid #e7ebef}.cim-chat-modal footer{border-top:1px solid #e7ebef;border-bottom:0;justify-content:flex-end;gap:8px}.cim-chat-modal header h2{margin:0}.cim-chat-modal header button{border:0;background:transparent;font-size:24px}.cim-chat-modal label{display:block;padding:10px 20px}.cim-chat-modal label span{display:block;margin-bottom:6px;font-size:12px;font-weight:700}.cim-chat-modal select,.cim-chat-modal textarea{width:100%;border:1px solid #dce2e8;border-radius:10px;padding:10px;font:inherit}.cim-chat-modal footer button{border:1px solid #dce2e8;background:#fff;border-radius:9px;padding:9px 14px}.cim-chat-modal footer .is-primary{background:#17212b;color:#fff;border-color:#17212b}.cim-chat-toast-root{position:fixed;right:20px;bottom:20px;z-index:100001}.cim-chat-toast{margin-top:8px;padding:12px 16px;background:#17212b;color:#fff;border-radius:10px;box-shadow:0 12px 28px rgba(0,0,0,.2)}.cim-chat-toast.is-error{background:#a92b2b}
@media(max-width:780px){.cim-chat-portal{border-radius:0;min-height:calc(100vh - 80px)}.cim-chat-shell{grid-template-columns:1fr;height:calc(100vh - 80px);max-height:none}.cim-chat-sidebar{display:flex}.cim-chat-main{display:none}.cim-chat-portal:has(.cim-chat-list-item.is-active) .cim-chat-sidebar{display:none}.cim-chat-portal:has(.cim-chat-list-item.is-active) .cim-chat-main{display:flex}.cim-chat-back{display:block}.cim-chat-bubble{max-width:90%}.cim-chat-floating strong{display:none}.cim-chat-floating{width:52px;height:52px;justify-content:center;padding:0}.cim-chat-composer{grid-template-columns:38px minmax(0,1fr) auto;padding:10px}.cim-chat-composer button{padding:0 12px}}
.cim-chat-connections-empty{font-size:11px;color:var(--chat-muted);padding:3px 2px}
.cim-chat-head{position:relative}.cim-chat-close-dialog{margin-left:auto;border:1px solid #dce2e8;background:#fff;border-radius:9px;padding:7px 10px;color:#687584;cursor:pointer;white-space:nowrap}
.cim-chat-toast.is-action{display:block;border:0;text-align:left;cursor:pointer;font:inherit}.cim-chat-toast.is-action::after{content:'Открыть';display:block;margin-top:4px;font-size:10px;opacity:.75}
@media(max-width:780px){.cim-chat-portal.is-chat-open .cim-chat-sidebar{display:none}.cim-chat-portal.is-chat-open .cim-chat-main{display:flex}.cim-chat-close-dialog{font-size:11px;padding:6px 8px}.cim-chat-head{padding:14px 10px}.cim-chat-head h2{font-size:17px}}
.cim-chat-modal input[type=search]{width:100%;border:1px solid #dce2e8;border-radius:10px;padding:10px;font:inherit}.cim-chat-field-help{display:block;margin-top:5px;color:#74808c;font-size:11px}.cim-chat-user-results{max-height:210px;overflow:auto;margin-top:6px;border-radius:9px}.cim-chat-user-results button{display:block;width:100%;padding:9px;border:0;border-bottom:1px solid #e5e9ed;background:#f7f9fb;text-align:left;cursor:pointer}.cim-chat-user-results button:hover{background:#eef3f7}.cim-chat-user-results strong,.cim-chat-user-results small{display:block}.cim-chat-user-results small{margin-top:3px;color:#74808c;font-size:11px}.cim-chat-user-results p{margin:0;padding:10px;color:#74808c;font-size:12px}

.cim-chat-list-item.is-unread{background:#fff7f7;border-left:3px solid #dc3e3e;padding-left:11px}.cim-chat-list-item.is-unread .cim-chat-list-item__body strong{font-weight:800}.cim-chat-list-item__meta b{min-width:20px;width:auto}.cim-chat-composer button[disabled],.cim-chat-modal button[disabled]{opacity:.55;cursor:wait}

/* v0.5: fixed-height conversation viewport and stable composer */
.cim-chat-portal{height:clamp(560px,calc(100dvh - 150px),820px);min-height:0}.cim-chat-shell{height:100%;max-height:none;min-height:0;overflow:hidden}.cim-chat-sidebar,.cim-chat-main{min-height:0;overflow:hidden}.cim-chat-main{position:relative}.cim-chat-head,.cim-chat-composer,.cim-chat-closed{flex:0 0 auto}.cim-chat-messages{min-height:0;overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain;scrollbar-gutter:stable}.cim-chat-composer{position:relative;z-index:3}.cim-chat-new-messages{position:absolute;right:22px;bottom:82px;z-index:5;border:0;border-radius:999px;background:#17212b;color:#fff;padding:9px 13px;box-shadow:0 8px 24px rgba(23,33,43,.25);cursor:pointer}.cim-chat-new-messages[hidden]{display:none}.cim-chat-composer textarea{resize:none;overflow-y:auto}.cim-chat-composer.is-sending{opacity:.72;pointer-events:none}
@media(max-width:780px){.cim-chat-portal{height:calc(100dvh - 70px);min-height:520px}.cim-chat-shell{height:100%;max-height:none}.cim-chat-new-messages{right:12px;bottom:72px}}


/* v0.7.3 — mobile guest CTA and inline image previews */
.cim-chat-list-empty span{display:block}.cim-chat-list-empty button{margin-top:16px;border:0;border-radius:11px;background:#17212b;color:#fff;padding:10px 15px;font-weight:700;cursor:pointer}.cim-chat-image{display:block;max-width:min(360px,100%);margin-top:8px;padding:0;border:0;border-radius:13px;background:transparent;overflow:hidden;cursor:zoom-in}.cim-chat-image img{display:block;width:100%;max-height:300px;object-fit:cover;border-radius:13px}.cim-chat-image-lightbox{position:fixed;inset:0;z-index:100005;display:none;place-items:center;padding:20px;background:rgba(10,18,26,.82);backdrop-filter:blur(5px)}.cim-chat-image-lightbox.is-open{display:grid}.cim-chat-image-lightbox>button{position:fixed;right:18px;top:16px;width:42px;height:42px;border:0;border-radius:12px;background:#fff;color:#17212b;font-size:28px;cursor:pointer}.cim-chat-image-lightbox figure{margin:0;max-width:94vw;max-height:90vh}.cim-chat-image-lightbox img{display:block;max-width:100%;max-height:84vh;border-radius:14px;object-fit:contain}.cim-chat-image-lightbox figcaption{margin-top:8px;color:#fff;text-align:center;font-size:12px}.cim-chat-lightbox-open{overflow:hidden}
@media(max-width:780px){.cim-chat-floating-modal__window .cim-chat-sidebar>header{padding-right:58px}.cim-chat-floating-modal__window .cim-chat-sidebar>header>button{flex:0 0 38px}.cim-chat-list-empty{padding:34px 24px}.cim-chat-list-empty button{min-width:190px}.cim-chat-image{max-width:86vw}.cim-chat-image img{max-height:240px}}


/* v0.7.5 - mobile close action and compact send button */
.cim-chat-image-lightbox{z-index:1000015}
.cim-chat-send svg{display:none;width:21px;height:21px}
@media(max-width:780px){
.cim-chat-head{min-height:108px;align-items:flex-start;padding:14px 10px 42px}
.cim-chat-head>div{min-width:0;flex:1;padding-right:6px}
.cim-chat-close-dialog{position:absolute;right:10px;bottom:9px;margin:0;font-size:11px;padding:7px 10px}
.cim-chat-composer{grid-template-columns:38px minmax(0,1fr) 44px;gap:8px;padding:10px 8px}
.cim-chat-composer textarea{min-width:0;padding:11px 12px}
.cim-chat-composer .cim-chat-send{display:grid;place-items:center;width:44px;height:44px;padding:0;border-radius:12px}
.cim-chat-composer .cim-chat-send span{display:none}
.cim-chat-composer .cim-chat-send svg{display:block}
.cim-chat-selected-files{grid-column:2/4}
}


/* v0.7.6 - mobile composer never overlaps its send action */
@media(max-width:780px){
  .cim-chat-composer{display:grid!important;grid-template-columns:40px minmax(0,1fr) 46px!important;gap:8px!important;align-items:end!important;box-sizing:border-box!important;padding:10px!important}
  .cim-chat-composer>*{min-width:0;box-sizing:border-box}
  .cim-chat-composer textarea{position:relative!important;inset:auto!important;width:100%!important;max-width:100%!important;margin:0!important;padding:11px 12px!important;box-sizing:border-box!important}
  .cim-chat-composer .cim-chat-send{position:relative!important;inset:auto!important;display:grid!important;place-items:center!important;width:46px!important;min-width:46px!important;max-width:46px!important;height:46px!important;margin:0!important;padding:0!important;transform:none!important}
  .cim-chat-attach{width:40px!important;min-width:40px!important;margin:0!important}
  .cim-chat-selected-files{grid-column:2/4!important;max-width:100%!important}
}

/* v0.9.0 — live typing and complete light/dark client chat */
.cim-chat-portal{--chat-bg:var(--cim-color-bg,#f5f7f9);--chat-surface:var(--cim-color-surface,#fff);--chat-surface-muted:var(--cim-color-surface-muted,#f8fafc);--chat-border:var(--cim-color-border,#e3e8ee);--chat-ink:var(--cim-color-heading,#17212b);--chat-text:var(--cim-color-text,#34414d);--chat-muted:var(--cim-color-text-secondary,#687584);background:var(--chat-surface);color:var(--chat-text);border-color:var(--chat-border)}
.cim-chat-sidebar{background:var(--chat-surface-muted);border-color:var(--chat-border)}.cim-chat-sidebar header,.cim-chat-sidebar__tools,.cim-chat-sidebar footer{border-color:var(--chat-border)}.cim-chat-sidebar h1,.cim-chat-list-item__body strong,.cim-chat-head h2{color:var(--chat-ink)}
.cim-chat-sidebar__tools button,.cim-chat-close-dialog{background:var(--chat-surface);border-color:var(--chat-border);color:var(--chat-text)}
.cim-chat-list-item{border-color:var(--chat-border);color:var(--chat-text)}.cim-chat-list-item:hover,.cim-chat-list-item.is-active{background:var(--chat-surface)}
.cim-chat-main{background:var(--chat-surface)}.cim-chat-head{border-color:var(--chat-border)}.cim-chat-messages{background:var(--chat-bg)}
.cim-chat-bubble{background:var(--chat-surface);border-color:var(--chat-border);color:var(--chat-text)}.cim-chat-message.is-own .cim-chat-bubble{background:#e9f3ff;border-color:#d2e7fb}
.cim-chat-composer{background:var(--chat-surface);border-color:var(--chat-border)}.cim-chat-composer textarea{background:var(--chat-surface);border-color:var(--chat-border);color:var(--chat-ink)}.cim-chat-attach{background:var(--chat-surface-muted);color:var(--chat-muted)}
.cim-chat-closed{background:var(--chat-surface-muted);border-color:var(--chat-border)}
.cim-chat-typing{flex:0 0 auto;display:flex;align-items:center;gap:7px;min-height:25px;padding:3px 18px 5px;background:var(--chat-surface);color:var(--chat-muted);font-size:11px}.cim-chat-typing[hidden]{display:none}.cim-chat-typing>span{display:inline-flex;gap:2px}.cim-chat-typing i{width:4px;height:4px;border-radius:50%;background:currentColor;animation:cim-client-typing 1.15s infinite ease-in-out}.cim-chat-typing i:nth-child(2){animation-delay:.13s}.cim-chat-typing i:nth-child(3){animation-delay:.26s}@keyframes cim-client-typing{0%,60%,100%{transform:translateY(0);opacity:.45}30%{transform:translateY(-3px);opacity:1}}
.cim-chat-portal button:focus-visible,.cim-chat-portal input:focus-visible,.cim-chat-portal select:focus-visible,.cim-chat-portal textarea:focus-visible,.cim-chat-portal a:focus-visible{outline:2px solid #f45a2a;outline-offset:2px}
html[data-cim-theme="dark"] .cim-chat-portal{--chat-bg:#111821;--chat-surface:#18212c;--chat-surface-muted:#141d27;--chat-border:#2c3947;--chat-ink:#f2f5f8;--chat-text:#d6dde5;--chat-muted:#91a0af}
html[data-cim-theme="dark"] .cim-chat-list-item.is-unread{background:#2e2024}html[data-cim-theme="dark"] .cim-chat-channel{background:#263443;color:#d6dde5}html[data-cim-theme="dark"] .cim-chat-channel.is-telegram{background:#18394c;color:#77c9f3}html[data-cim-theme="dark"] .cim-chat-channel.is-max{background:#30284a;color:#b6a9ff}
html[data-cim-theme="dark"] .cim-chat-message.is-own .cim-chat-bubble{background:#1d3550;border-color:#2e4d6c}html[data-cim-theme="dark"] .cim-chat-file{background:rgba(255,255,255,.06);color:var(--chat-text)}
html[data-cim-theme="dark"] .cim-chat-modal form{background:var(--chat-surface);color:var(--chat-text)}html[data-cim-theme="dark"] .cim-chat-modal header,html[data-cim-theme="dark"] .cim-chat-modal footer{border-color:var(--chat-border)}html[data-cim-theme="dark"] .cim-chat-modal input,html[data-cim-theme="dark"] .cim-chat-modal select,html[data-cim-theme="dark"] .cim-chat-modal textarea{background:var(--chat-surface-muted);border-color:var(--chat-border);color:var(--chat-ink)}html[data-cim-theme="dark"] .cim-chat-modal footer button{background:var(--chat-surface-muted);border-color:var(--chat-border);color:var(--chat-text)}html[data-cim-theme="dark"] .cim-chat-user-results button{background:var(--chat-surface-muted);border-color:var(--chat-border);color:var(--chat-text)}
@media(max-width:780px){.cim-chat-typing{padding:3px 10px 5px}}
@media(prefers-reduced-motion:reduce){.cim-chat-portal *{scroll-behavior:auto!important;animation-duration:.001ms!important;animation-iteration-count:1!important;transition-duration:.001ms!important}}


/* CIM Messaging 0.9.2: client-side read receipt */
.cim-chat-read-receipt{display:flex;justify-content:flex-end;align-items:center;margin-top:4px;height:13px;color:#4a809f}
.cim-chat-read-receipt[hidden]{display:none!important}
.cim-chat-read-receipt svg{display:block;width:13px;height:13px}
html[data-cim-theme="dark"] .cim-chat-read-receipt{color:#78aeca}

/* ===== CIM Messaging 0.9.3: client-side quote blocks ===== */
.cim-chat-reply-block{
  display:block;
  width:100%;
  margin:7px 0 5px;
  padding:7px 9px;
  border:0;
  border-left:3px solid var(--chat-accent,#f0612c);
  border-radius:8px;
  background:color-mix(in srgb,var(--chat-text) 5%,var(--chat-surface));
  color:var(--chat-text);
  text-align:left;
  cursor:pointer;
  font:inherit;
}
.cim-chat-reply-block strong,.cim-chat-reply-block span{display:block;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.cim-chat-reply-block strong{font-size:10px;font-weight:800}
.cim-chat-reply-block span{margin-top:2px;font-size:11px;color:var(--chat-muted)}
.cim-chat-message.is-reply-target .cim-chat-bubble{animation:cim-chat-reply-focus .9s ease}
@keyframes cim-chat-reply-focus{0%,100%{box-shadow:none}40%{box-shadow:0 0 0 4px color-mix(in srgb,var(--chat-accent,#f0612c) 20%,transparent)}}
@media(prefers-reduced-motion:reduce){.cim-chat-message.is-reply-target .cim-chat-bubble{animation:none;outline:2px solid color-mix(in srgb,var(--chat-accent,#f0612c) 35%,transparent)}}
