:root{
  /* Палитра Telegram Web K (тёмная тема): тёмно-синий фон, фиолетовый акцент. */
  --bg:#0e0e18; --bg2:#17212b; --bg3:#242f3d; --bg-hover:#202b36;
  --accent:#8774e1; --accent2:#6c5ce7;
  --text1:#e4e7eb; --text2:#8296a8; --text3:#5c6b7a; --danger:#e05252; --radius:16px;
  --bubble-out:#8774e1; --bubble-in:#212d3b;
}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{font-family:-apple-system,Segoe UI,Roboto,Arial,sans-serif;background:var(--bg);color:var(--text1);overflow:hidden}
button{font-family:inherit;cursor:pointer;border:none;background:none;color:inherit}
input,textarea{font-family:inherit;color:inherit;background:none;border:none;outline:none}
img{max-width:100%}
svg{display:block}
.hidden{display:none !important}

/* ── экран входа ── */
#authScreen{height:100%;display:flex;align-items:center;justify-content:center;flex-direction:column;gap:20px;background:radial-gradient(circle at 50% 0%, #1b2836, var(--bg))}
#authScreen .logo{width:88px;height:88px;object-fit:contain;filter:drop-shadow(0 6px 18px rgba(135,116,225,.35))}
.authCard{background:var(--bg2);border-radius:20px;padding:32px;width:320px;display:flex;flex-direction:column;gap:14px}
.authCard h2{margin:0;font-size:18px}
.authCard input{background:var(--bg3);border-radius:12px;padding:14px;font-size:15px}
.authCard button.primary{background:var(--accent);border-radius:12px;padding:14px;font-size:15px;font-weight:600;text-align:center;transition:filter .15s}
.authCard button.primary:hover{filter:brightness(1.08)}
.authCard button.primary:active{filter:brightness(.9)}
.authCard .muted{color:var(--text2);font-size:13px;text-align:center}
.authError{color:var(--danger);font-size:13px;min-height:18px}

/* ── общий каркас: список чатов | переписка ── */
#app{display:none;height:100%;grid-template-columns:360px 1fr;grid-template-rows:100%}
#app.shown{display:grid}
#sidebar{background:var(--bg2);display:flex;flex-direction:column;border-right:1px solid #0b131a}

#sidebarHeader{display:flex;align-items:center;gap:6px;padding:10px 12px;height:56px}
.iconBtn{width:40px;height:40px;border-radius:50%;flex:0 0 auto;display:flex;align-items:center;justify-content:center;color:var(--text2);transition:background .15s,color .15s}
.iconBtn:hover{background:var(--bg-hover);color:var(--text1)}
#headerSearch{flex:1;display:flex;align-items:center;gap:8px;background:var(--bg3);border-radius:20px;padding:0 14px;height:40px}
#headerSearch .searchIcon{color:var(--text3);display:flex}
#headerSearch input{flex:1;font-size:14px;height:100%}

#folderTabs{display:flex;gap:4px;padding:2px 10px 8px;overflow-x:auto;scrollbar-width:none}
#folderTabs::-webkit-scrollbar{display:none}
.folderTab{flex:0 0 auto;padding:7px 14px;border-radius:16px;font-size:14px;color:var(--text2);white-space:nowrap;transition:background .15s,color .15s}
.folderTab:hover{background:var(--bg-hover)}
.folderTab.active{background:var(--accent);color:#fff}

#chatList{flex:1;overflow-y:auto}
.chatRow{display:flex;gap:12px;padding:9px 12px;align-items:center;cursor:pointer;border-radius:10px;margin:0 6px;transition:background .1s}
.chatRow:hover{background:var(--bg-hover)}
.chatRow.active{background:var(--accent)}
.chatRow.active .preview,.chatRow.active .time{color:rgba(255,255,255,.75) !important}
.chatRow.active .name{color:#fff}
.avatar{width:52px;height:52px;border-radius:50%;flex:0 0 auto;display:flex;align-items:center;justify-content:center;
  font-weight:600;color:#fff;font-size:19px;background-size:cover;background-position:center}
.chatMeta{flex:1;min-width:0;display:flex;flex-direction:column;gap:3px}
.chatMeta .row1{display:flex;align-items:baseline;justify-content:space-between;gap:8px}
.chatMeta .name{font-size:15px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:flex;align-items:center;gap:5px}
.chatMeta .name .pinIcon{color:var(--text3);flex:0 0 auto}
.chatMeta .time{font-size:12px;color:var(--text3);flex:0 0 auto}
.chatMeta .row2{display:flex;align-items:center;justify-content:space-between;gap:8px}
.chatMeta .preview{font-size:13.5px;color:var(--text2);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chatMeta .preview.draft{color:var(--danger)}
.badge{background:var(--accent2);color:#fff;font-size:12px;border-radius:10px;min-width:20px;height:20px;
  display:flex;align-items:center;justify-content:center;padding:0 6px;flex:0 0 auto}
.badge.muted{background:var(--text3)}
.mutedIcon{color:var(--text3);flex:0 0 auto;display:flex}

/* ── правая часть: чат ── */
#chatPane{display:flex;flex-direction:column;height:100%;background:#0f151c;
  background-image:radial-gradient(circle at 15% 8%, rgba(135,116,225,.05), transparent 45%)}
#emptyState{flex:1;display:flex;align-items:center;justify-content:center;flex-direction:column;gap:14px;color:var(--text3);font-size:15px}
#emptyState .emptyLogo{width:72px;height:72px;object-fit:contain;opacity:.5}
#chatHeader{display:none;align-items:center;gap:12px;padding:8px 20px;height:56px;border-bottom:1px solid #0b131a;background:var(--bg2)}
#chatHeader.shown{display:flex}
#chatHeader .info{flex:1;min-width:0}
#chatHeader .name{font-weight:600;font-size:15px}
#chatHeader .status{font-size:12.5px;color:var(--text2)}
#chatHeader .actions{display:flex;gap:2px}
#messages{flex:1;overflow-y:auto;padding:16px 24px;display:flex;flex-direction:column;gap:2px}
.msgRow{display:flex;margin-bottom:6px}
.msgRow.out{justify-content:flex-end}
.bubble{max-width:60%;padding:8px 12px;border-radius:14px;font-size:14.5px;line-height:1.4;position:relative;cursor:default}
.msgRow.in .bubble{background:var(--bubble-in);border-bottom-left-radius:4px}
.msgRow.out .bubble{background:var(--bubble-out);border-bottom-right-radius:4px}
.bubble .sender{font-size:13px;font-weight:600;color:#9b8cff;margin-bottom:2px}
.bubble .time{font-size:10.5px;opacity:.6;margin-top:3px;text-align:right}
.bubble .media img,.bubble .media video{border-radius:10px;max-height:280px;display:block;margin-bottom:4px;cursor:pointer}
.bubble .file{display:flex;align-items:center;gap:8px;background:rgba(255,255,255,.08);padding:8px 10px;border-radius:10px;margin-bottom:4px}
.bubble .lockedMsg{display:flex;align-items:center;gap:6px;opacity:.7}
.bubble .reactions{display:flex;gap:4px;margin-top:4px;flex-wrap:wrap}
.reactionChip{background:rgba(255,255,255,.12);border-radius:10px;padding:1px 6px;font-size:12px;cursor:pointer}
.reactionChip.mine{background:rgba(255,255,255,.28)}
#composer{display:none;align-items:flex-end;gap:8px;padding:10px 16px;border-top:1px solid #0b131a;background:var(--bg2)}
#composer.shown{display:flex}
#composer textarea{flex:1;background:var(--bg3);border-radius:20px;padding:11px 16px;font-size:14.5px;max-height:120px;resize:none}
.sendBtn{width:42px;height:42px;border-radius:50%;background:var(--accent);display:flex;align-items:center;justify-content:center;color:#fff;flex:0 0 auto}
.sendBtn svg{margin-left:2px}

/* ── модалки / контекстные меню (в духе Telegram) ── */
.overlay{position:fixed;inset:0;background:rgba(0,0,0,.5);display:flex;align-items:center;justify-content:center;z-index:50}
.modal{background:var(--bg2);border-radius:14px;padding:8px;width:280px;max-width:90vw;display:flex;flex-direction:column;max-height:80vh;overflow-y:auto;box-shadow:0 12px 40px rgba(0,0,0,.5)}
.modal h3{margin:6px 10px 4px;font-size:15px;font-weight:600;color:var(--text2)}
.modal input,.modal select{background:var(--bg3);border-radius:10px;padding:10px 12px;font-size:14px;width:100%;margin:4px 6px;width:calc(100% - 12px)}
.modal .row{display:flex;gap:8px;justify-content:flex-end;margin:8px 6px 4px}
.modal button.ghost{color:var(--text2);padding:8px 12px;border-radius:8px}
.modal button.ghost:hover{background:var(--bg-hover)}
.modal button.primary{background:var(--accent);color:#fff;border-radius:8px;padding:9px 16px;font-weight:600}
.menuRow{display:flex;align-items:center;gap:12px;padding:10px 12px;border-radius:8px;font-size:14.5px;color:var(--text1);text-align:left;width:100%}
.menuRow:hover{background:var(--bg-hover)}
.menuRow.danger{color:var(--danger)}
.menuRow .ico{color:var(--text2);display:flex;flex:0 0 auto}
.menuRow.danger .ico{color:var(--danger)}
.menuDivider{height:1px;background:#0b131a;margin:4px 8px}
.searchResultRow{display:flex;gap:10px;align-items:center;padding:8px;border-radius:10px;cursor:pointer}
.searchResultRow:hover{background:var(--bg-hover)}

/* ── звонок ── */
#callOverlay{position:fixed;inset:0;background:#0b0f14;display:none;flex-direction:column;z-index:100}
#callOverlay.shown{display:flex}
#remoteVideo{flex:1;width:100%;object-fit:cover;background:#12171d}
#localVideo{position:absolute;width:130px;height:180px;border-radius:14px;right:16px;bottom:120px;object-fit:cover;
  background:#1a2028;box-shadow:0 4px 20px rgba(0,0,0,.5);cursor:grab}
#callTop{position:absolute;top:28px;left:0;right:0;text-align:center;color:#fff}
#callTop .name{font-size:20px;font-weight:600}
#callTop .status{font-size:13px;color:#9aa7b2;margin-top:4px}
#callControls{position:absolute;bottom:36px;left:0;right:0;display:flex;justify-content:center;gap:22px}
.callBtn{width:56px;height:56px;border-radius:50%;background:rgba(255,255,255,.12);color:#fff;display:flex;align-items:center;justify-content:center}
.callBtn.end{background:var(--danger)}
.callBtn.active{background:#fff;color:#111}
#incomingCallBar{position:fixed;top:16px;right:16px;background:var(--bg2);border-radius:14px;padding:12px 16px;display:none;
  align-items:center;gap:12px;z-index:90;box-shadow:0 8px 30px rgba(0,0,0,.45)}
#incomingCallBar.shown{display:flex}
#incomingCallBar .callBtn{background:rgba(255,255,255,.08)}

/* ── тост ── */
#toast{position:fixed;bottom:24px;left:50%;transform:translateX(-50%);background:#2b3542;color:#fff;
  padding:12px 20px;border-radius:14px;font-size:14px;opacity:0;transition:opacity .2s,transform .2s;z-index:200;pointer-events:none}
#toast.shown{opacity:1;transform:translateX(-50%) translateY(-6px)}

::-webkit-scrollbar{width:8px}
::-webkit-scrollbar-thumb{background:var(--bg3);border-radius:4px}
