@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

*,:before,:after{box-sizing:border-box;margin:0;padding:0}

/* ══ DARK THEME (default) ══════════════════════════════ */
:root{
  --bg:#0d1014;--bg2:#181d23;--bg3:#1b2129;--bg4:#151b21;--bg-bar:#101418;
  --accent:#3ddbb0;--accent-fg:#07120f;--accent2:#2cbf95;
  --t1:#e8ecef;--t2:rgba(232,236,239,.5);--t3:rgba(232,236,239,.4);
  --border:rgba(255,255,255,.07);
  --success:#3ddbb0;--danger:#f87171;--warn:#e0a458;
  --msg-out:#16332c;--msg-out-text:#dff5ee;--msg-in:#181d23;--msg-in-text:#e2e7ea;
  --radius:12px;
  --overlay:rgba(0,0,0,.75);
  --shadow:0 4px 24px rgba(0,0,0,.6);
  --mono:'IBM Plex Mono',ui-monospace,monospace;
}

/* ══ LIGHT THEME ════════════════════════════════════════ */
[data-theme="light"]{
  --bg:#f0f3f7;--bg2:#ffffff;--bg3:#e8ecf0;--bg4:#f4f6f9;--bg-bar:#ffffff;
  --accent:#1aaa7c;--accent-fg:#ffffff;--accent2:#15896a;
  --t1:#0f1318;--t2:rgba(15,19,24,.65);--t3:rgba(15,19,24,.4);
  --border:rgba(0,0,0,.09);
  --msg-out:#1aaa7c;--msg-out-text:#ffffff;--msg-in:#f0f3f7;--msg-in-text:#0f1318;
  --overlay:rgba(0,0,0,.4);
  --shadow:0 4px 20px rgba(0,0,0,.12);
}
[data-theme="light"] .msg-bubble{color:var(--msg-in-text)}
[data-theme="light"] .msg-row.out .msg-bubble{color:var(--msg-out-text)}

/* ══ BASE ═══════════════════════════════════════════════ */
html,body{height:100%;overflow:hidden;font-family:'IBM Plex Sans','Segoe UI',system-ui,sans-serif;font-size:14px;background:var(--bg);color:var(--t1)}
*::-webkit-scrollbar{width:3px;height:3px}
*::-webkit-scrollbar-track{background:transparent}
*::-webkit-scrollbar-thumb{background:rgba(128,128,128,.25);border-radius:4px}

/* ══ LAYOUT ═════════════════════════════════════════════ */
#app{display:flex;height:100vh;overflow:hidden}

/* ══ LOGIN ══════════════════════════════════════════════ */
#loginScreen{position:fixed;inset:0;z-index:100;background:var(--bg);display:flex;align-items:center;justify-content:center}
.login-wrap{width:100%;max-width:380px;padding:32px 24px;display:flex;flex-direction:column;align-items:center;gap:20px}
.login-logo{width:72px;height:72px;border-radius:18px;object-fit:contain}
.login-brand{font-size:22px;font-weight:700;letter-spacing:-.3px}
.login-sub{font-size:13px;color:var(--t3);margin-top:2px;text-align:center}
.login-card{width:100%;background:var(--bg2);border-radius:16px;padding:20px;display:flex;flex-direction:column;gap:14px}
.login-card-title{font-size:11px;font-weight:600;color:var(--t3);text-transform:uppercase;letter-spacing:.6px}
.field{display:flex;flex-direction:column;gap:6px}
.field label{font-size:12px;color:var(--t2)}
.field input,.field select{
  background:var(--bg4);border:1px solid var(--border);border-radius:8px;
  color:var(--t1);font-size:15px;padding:10px 12px;outline:none;
  font-family:inherit;width:100%;transition:border-color .15s;
}
.field input:focus{border-color:var(--accent)}
.field input::placeholder{color:var(--t3)}
.btn{width:100%;padding:12px;border-radius:10px;border:none;font-size:15px;font-weight:600;font-family:inherit;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:8px;transition:opacity .15s}
.btn:active{opacity:.8}
.btn-primary{background:var(--accent);color:var(--accent-fg)}
.btn-secondary{background:var(--bg3);color:var(--t1)}
.btn-danger{background:#c0392b;color:#fff}
.err-msg{font-size:12px;color:var(--danger);text-align:center;display:none}
.login-hint{font-size:12px;color:var(--t3);text-align:center;line-height:1.5}
.cfg-toggle{background:none;border:none;color:var(--t3);font-size:12px;cursor:pointer;text-decoration:underline;margin-top:-6px}
.cfg-section{display:none;width:100%;background:var(--bg2);border-radius:16px;padding:16px;flex-direction:column;gap:12px}
.login-divider{width:100%;display:flex;align-items:center;gap:10px;color:var(--t3);font-size:12px}
.login-divider::before,.login-divider::after{content:'';flex:1;height:1px;background:var(--border)}

/* ══ PHONE AUTH SCREENS ══════════════════════════════════ */
#authPhoneScreen,#authOtpScreen,#authProfileScreen{
  position:fixed;inset:0;display:none;align-items:center;justify-content:center;
  background:var(--bg);z-index:200;
}
.auth-wrap{width:100%;max-width:380px;padding:32px 24px;display:flex;flex-direction:column;align-items:center;gap:20px;position:relative}
.auth-back-btn{position:absolute;top:0;left:0;background:none;border:none;color:var(--t2);cursor:pointer;padding:4px;border-radius:8px}
.auth-back-btn:hover{background:var(--bg3)}
.auth-logo{width:80px;height:80px;border-radius:24px;background:var(--bg2);display:flex;align-items:center;justify-content:center}
.auth-title{font-size:22px;font-weight:700;letter-spacing:-.3px;text-align:center}
.auth-sub{font-size:14px;color:var(--t2);text-align:center;line-height:1.5}
.auth-field{width:100%}
.auth-input{
  width:100%;background:var(--bg2);border:1.5px solid var(--border);border-radius:12px;
  color:var(--t1);font-size:16px;padding:14px 16px;outline:none;font-family:inherit;
  box-sizing:border-box;transition:border-color .15s;
}
.auth-input:focus{border-color:var(--accent)}
.auth-input::placeholder{color:var(--t3)}
.auth-error{font-size:13px;color:var(--danger);text-align:center;min-height:18px}
.auth-btn{width:100%;padding:14px;font-size:16px}
.otp-boxes{display:flex;gap:10px;justify-content:center}
.otp-box{
  width:44px;height:54px;border-radius:12px;border:1.5px solid var(--border);
  background:var(--bg2);color:var(--t1);font-size:22px;font-weight:700;
  text-align:center;outline:none;font-family:inherit;caret-color:var(--accent);
  transition:border-color .15s;
}
.otp-box:focus{border-color:var(--accent)}
.auth-resend{font-size:13px;color:var(--t3);text-align:center}
.link-btn{background:none;border:none;color:var(--accent);font-size:13px;cursor:pointer;font-family:inherit;padding:0;text-decoration:underline}
.link-btn:disabled{color:var(--t3);text-decoration:none;cursor:default}
.auth-colors{display:flex;gap:12px;flex-wrap:wrap;justify-content:center}
.auth-color-dot{width:36px;height:36px;border-radius:50%;cursor:pointer;transition:transform .15s,box-shadow .15s}
.auth-color-dot:hover{transform:scale(1.1)}
.auth-color-dot.selected{box-shadow:0 0 0 3px var(--bg),0 0 0 5px var(--accent);transform:scale(1.1)}

/* ══ SIDEBAR ════════════════════════════════════════════ */
#sidebar{width:320px;min-width:320px;display:flex;flex-direction:column;background:var(--bg);border-right:1px solid var(--border)}
.sidebar-hdr{padding:10px 12px;display:flex;align-items:center;gap:8px;border-bottom:1px solid var(--border)}
.sidebar-title{font-size:16px;font-weight:700;flex:1}
.icon-btn{width:32px;height:32px;border-radius:50%;border:none;background:transparent;color:var(--t2);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s;flex-shrink:0}
.icon-btn:hover{background:var(--bg3)}
.icon-btn svg{pointer-events:none}
.sidebar-search{padding:8px 12px;border-bottom:1px solid var(--border)}
.sidebar-search input{width:100%;background:var(--bg4);border:1px solid var(--border);border-radius:8px;color:var(--t1);font-size:13px;padding:7px 10px;outline:none;font-family:inherit}
/* ══ ROOM LIST (Telegram-style) ════════════════════════ */
.room-list{flex:1;overflow-y:auto;overscroll-behavior:contain}
.rooms-empty{padding:32px 20px;text-align:center;color:var(--t3);font-size:14px}

.room-item{
  padding:9px 14px 9px 12px;display:flex;align-items:center;gap:10px;
  cursor:pointer;user-select:none;-webkit-user-select:none;
  transition:background .12s;position:relative;
}
.room-item::after{content:'';position:absolute;left:66px;right:0;bottom:0;height:1px;background:var(--border)}
.room-item:last-child::after{display:none}
.room-item:active,.room-item.active{background:var(--bg3)}
@media(hover:hover){.room-item:hover{background:var(--bg3)}}

/* Avatar */
.room-avatar{
  width:46px;height:46px;border-radius:13px;flex-shrink:0;position:relative;
  display:flex;align-items:center;justify-content:center;
  font-size:16px;font-weight:600;color:#fff;letter-spacing:-.3px;
  background-size:cover;background-position:center;
}
.room-type-icon{
  position:absolute;bottom:-1px;right:-1px;width:18px;height:18px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  font-size:9px;font-weight:800;border:2px solid var(--bg2);
}
.room-type-icon.ch{background:#2b9cf2;color:#fff}
.room-type-icon.gr{background:#8e44ad;color:#fff}
.room-online-dot{
  position:absolute;bottom:0;right:0;width:13px;height:13px;border-radius:50%;
  background:var(--success);border:2.5px solid var(--bg2);
}

/* Info block */
.room-info{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}
.room-name-row{display:flex;align-items:center;gap:4px}
.room-name{
  font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
  flex:1;line-height:1.2;
}
.room-muted-ico{color:var(--t3);flex-shrink:0;display:flex}
.room-pin-ico{color:var(--t3);flex-shrink:0;display:flex;display:none}
.room-time{
  font-size:12px;color:var(--t3);flex-shrink:0;white-space:nowrap;
  display:flex;align-items:center;gap:3px;
}
.room-ticks{color:var(--accent);font-size:10px;line-height:1}
.room-ticks svg{display:inline-block;vertical-align:middle}

/* Preview row */
.room-preview{
  font-size:13px;color:var(--t3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
  flex:1;line-height:1.3;
}
.preview-you{color:var(--accent);font-weight:500}
.preview-sender{color:var(--t2);font-weight:500}

/* Unread badge */
.unread-badge{
  background:var(--accent);color:var(--accent-fg);border-radius:12px;
  font-size:11px;font-weight:700;padding:2px 7px;min-width:20px;
  text-align:center;flex-shrink:0;line-height:1.4;
}
.unread-badge.muted{background:var(--bg4);color:var(--t3)}
.pinned-room-ico{color:var(--t3);flex-shrink:0}

/* ══ BOTTOM SHEET ═══════════════════════════════════════ */
.bottom-sheet-overlay{
  position:fixed;inset:0;z-index:300;background:rgba(0,0,0,.55);
  opacity:0;pointer-events:none;transition:opacity .2s;
}
.bottom-sheet-overlay.open{opacity:1;pointer-events:all}

.bottom-sheet{
  position:fixed;left:0;right:0;bottom:0;z-index:301;
  background:var(--bg2);border-radius:18px 18px 0 0;
  transform:translateY(100%);transition:transform .25s cubic-bezier(.4,0,.2,1);
  max-height:88vh;overflow-y:auto;overscroll-behavior:contain;
  padding-bottom:env(safe-area-inset-bottom,16px);
  box-shadow:0 -4px 32px rgba(0,0,0,.4);
}
.bottom-sheet.open{transform:translateY(0)}

.bs-chat-header{
  display:flex;align-items:center;gap:12px;padding:16px 20px 12px;
  border-bottom:1px solid var(--border);
}
.bs-chat-av{
  width:42px;height:42px;border-radius:50%;flex-shrink:0;
  display:flex;align-items:center;justify-content:center;
  font-size:17px;font-weight:700;color:#fff;
}
.bs-chat-name{font-size:16px;font-weight:700}
.bs-title{
  font-size:13px;font-weight:700;color:var(--t3);text-transform:uppercase;
  letter-spacing:.6px;padding:16px 20px 8px;
}
.bs-items{display:flex;flex-direction:column;padding:4px 0 8px}
.bs-item{
  display:flex;align-items:center;gap:14px;padding:14px 20px;
  background:none;border:none;color:var(--t1);font-size:15px;
  font-family:inherit;cursor:pointer;text-align:left;
  transition:background .1s;
}
.bs-item:active{background:var(--bg3)}
@media(hover:hover){.bs-item:hover{background:var(--bg3)}}
.bs-item svg{color:var(--t2);flex-shrink:0}
.bs-item.warn{color:var(--warn)}
.bs-item.warn svg{color:var(--warn)}
.bs-item.danger{color:var(--danger)}
.bs-item.danger svg{color:var(--danger)}
.bs-divider{height:1px;background:var(--border);margin:4px 0}

/* ══ CHAT AREA ══════════════════════════════════════════ */
#chatArea{flex:1;display:flex;flex-direction:column;background:var(--bg);overflow:hidden}
.chat-empty{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;color:var(--t3)}
.chat-hdr{padding:10px 14px;display:flex;align-items:center;gap:10px;background:var(--bg2);border-bottom:1px solid var(--border);flex-shrink:0}
.chat-hdr-back{display:none}
.chat-hdr-info{flex:1;overflow:hidden;cursor:pointer}
.chat-hdr-name{font-size:15px;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chat-hdr-sub{font-size:12px;color:var(--t3);display:flex;align-items:center;gap:4px}
.chat-hdr-actions{display:flex;gap:4px}

/* ══ PINNED BAR ═════════════════════════════════════════ */
.pinned-bar{
  padding:6px 14px;display:flex;align-items:center;gap:8px;
  background:var(--bg3);border-bottom:1px solid var(--border);cursor:pointer;
  font-size:12px;
}
.pinned-bar svg{flex-shrink:0;color:var(--accent)}
.pinned-bar-text{flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color:var(--t2)}

/* ══ MESSAGES ═══════════════════════════════════════════ */
.messages{flex:1;overflow-y:auto;padding:10px 12px;display:flex;flex-direction:column;gap:2px}
.msg-row{display:flex;align-items:flex-end;gap:6px;margin-bottom:1px;transition:background .2s}
.msg-row.out{flex-direction:row-reverse}
.msg-row.swipe-hint{background:rgba(43,156,242,.07);border-radius:8px}
.msg-avatar{width:28px;height:28px;border-radius:9px;background:var(--bg3);display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:700;color:#fff;flex-shrink:0}
.msg-row.out .msg-avatar{display:none}
.msg-bubble{max-width:72%;padding:7px 10px 4px;border-radius:12px;background:var(--msg-in);position:relative;word-break:break-word;user-select:text}
.msg-row.out .msg-bubble{background:var(--msg-out);border-bottom-right-radius:4px;color:var(--msg-out-text)}
.msg-row.in .msg-bubble{border-bottom-left-radius:4px;color:var(--msg-in-text)}
.msg-sender{font-size:11px;font-weight:600;color:var(--accent);margin-bottom:2px}
.msg-text{font-size:14px;line-height:1.45;white-space:pre-wrap}
.msg-text.deleted{color:var(--t3);font-style:italic}
.msg-footer{display:flex;align-items:center;justify-content:flex-end;gap:4px;margin-top:3px;flex-wrap:wrap-reverse}
.msg-time{font-size:10px;color:var(--t3)}
.msg-edited{font-size:10px;color:var(--t3)}
.msg-checks{display:flex;align-items:center;color:var(--t3)}
.msg-checks.read{color:var(--accent)}
.msg-system{text-align:center;color:var(--t3);font-size:12px;padding:4px 8px;margin:4px 0}
.date-sep{text-align:center;color:var(--t3);font-size:11px;padding:8px 0}

/* Reply quote */
.msg-reply{border-left:2px solid var(--accent);padding:3px 8px;margin-bottom:4px;border-radius:4px;background:rgba(43,156,242,.08);font-size:12px;cursor:pointer}
.msg-reply-sender{color:var(--accent);font-weight:600;font-size:11px}
.msg-reply-text{color:var(--t2);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* Media messages */
.msg-img{max-width:100%;max-height:260px;border-radius:8px;cursor:pointer;display:block}
.msg-file-card{display:flex;align-items:center;gap:10px;background:rgba(0,0,0,.15);border-radius:8px;padding:8px 10px;cursor:pointer;min-width:180px}
.msg-file-info{flex:1;overflow:hidden}
.msg-file-name{font-size:12px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.msg-file-size{font-size:10px;color:var(--t3)}

/* Voice message */
.msg-voice{display:flex;align-items:center;gap:8px;min-width:180px;max-width:280px}
.voice-play-btn{width:32px;height:32px;border-radius:50%;background:var(--accent);border:none;color:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;flex-shrink:0}
.voice-wave{flex:1;height:28px;cursor:pointer;position:relative}
.voice-wave-bar{width:100%;height:100%;background:rgba(43,156,242,.3);border-radius:4px;overflow:hidden;position:relative}
.voice-wave-fill{height:100%;background:var(--accent);border-radius:4px;transition:width .1s linear}
.voice-dur{font-size:11px;color:var(--t3);flex-shrink:0}

/* Link preview */
.msg-link-preview{border:1px solid var(--border);border-radius:8px;overflow:hidden;margin-top:6px;cursor:pointer;max-width:280px}
.msg-link-preview img{width:100%;height:100px;object-fit:cover}
.msg-link-body{padding:6px 8px}
.msg-link-title{font-size:12px;font-weight:600;line-height:1.3}
.msg-link-desc{font-size:11px;color:var(--t3);margin-top:2px;line-height:1.3;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.msg-link-url{font-size:10px;color:var(--accent);margin-top:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* Reactions */
.msg-reactions{display:flex;flex-wrap:wrap;gap:4px;margin-top:4px}
.reaction-pill{
  display:inline-flex;align-items:center;gap:3px;
  background:var(--bg3);border-radius:12px;padding:2px 7px;font-size:13px;cursor:pointer;
  border:1px solid transparent;transition:all .15s;user-select:none;
}
.reaction-pill:hover{border-color:var(--accent)}
.reaction-pill.mine{background:rgba(43,156,242,.2);border-color:var(--accent)}
.reaction-pill .rc{font-size:14px}
.reaction-pill .rc-count{font-size:11px;color:var(--t2);font-weight:600}

/* ══ INPUT AREA ═════════════════════════════════════════ */
.reply-bar{padding:6px 12px;display:none;align-items:center;gap:8px;background:var(--bg3);border-top:1px solid var(--border);font-size:12px}
.reply-bar-text{flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color:var(--t2)}
.reply-bar-close{background:none;border:none;color:var(--t3);cursor:pointer;display:flex;align-items:center;justify-content:center}
.input-area{padding:8px 10px;display:flex;align-items:flex-end;gap:6px;background:var(--bg-bar);border-top:1px solid var(--border);flex-shrink:0}
.input-box{flex:1;background:var(--bg4);border:1px solid var(--border);border-radius:20px;color:var(--t1);font-size:14px;padding:8px 14px;outline:none;font-family:inherit;resize:none;max-height:120px;overflow-y:auto;line-height:1.4}
.input-box::placeholder{color:var(--t3)}
.send-btn{width:36px;height:36px;border-radius:12px;border:none;background:var(--accent);color:var(--accent-fg);font-size:16px;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:background .15s}
.send-btn:hover{background:var(--accent2)}

/* Recording bar */
.recording-bar{padding:8px 12px;display:none;align-items:center;gap:8px;background:var(--bg3);border-top:1px solid var(--border)}
.recording-dot{width:8px;height:8px;border-radius:50%;background:var(--danger);animation:pulse 1s infinite}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.3}}
.recording-timer{font-size:13px;font-weight:600;color:var(--t1);min-width:40px}
.recording-cancel{background:none;border:none;color:var(--danger);cursor:pointer;font-size:12px;margin-left:auto;display:flex;align-items:center;gap:4px}

/* ══ TYPING INDICATOR ═══════════════════════════════════ */
.typing-ind{padding:4px 12px;font-size:12px;color:var(--t3);height:22px;display:flex;align-items:center;gap:6px}
.typing-dots{display:flex;gap:3px}
.typing-dots span{width:4px;height:4px;border-radius:50%;background:var(--t3);animation:td .9s infinite}
.typing-dots span:nth-child(2){animation-delay:.15s}
.typing-dots span:nth-child(3){animation-delay:.3s}
@keyframes td{0%,60%,100%{transform:translateY(0)}30%{transform:translateY(-4px)}}

/* ══ TOAST ══════════════════════════════════════════════ */
.toast{position:fixed;bottom:80px;left:50%;transform:translateX(-50%);background:var(--bg3);color:var(--t1);padding:8px 18px;border-radius:20px;font-size:13px;opacity:0;transition:opacity .2s;pointer-events:none;z-index:999;white-space:nowrap}
.toast.show{opacity:1}

/* ══ MODALS ═════════════════════════════════════════════ */
.modal-overlay{position:fixed;inset:0;z-index:50;background:var(--overlay);display:none;align-items:center;justify-content:center}
.modal-overlay.open{display:flex}
.modal-box{background:var(--bg2);border-radius:16px;padding:20px;width:90%;max-width:420px;display:flex;flex-direction:column;gap:14px;max-height:90vh;overflow:hidden}
.modal-hdr{display:flex;align-items:center;justify-content:space-between}
.modal-title{font-size:16px;font-weight:700}
.modal-body{overflow-y:auto;flex:1}

/* Context menu */
#ctxMenu{position:fixed;z-index:200;background:var(--bg2);border-radius:10px;padding:6px;display:none;flex-direction:column;gap:2px;box-shadow:var(--shadow);min-width:160px}
.ctx-item{background:none;border:none;color:var(--t1);padding:8px 12px;text-align:left;cursor:pointer;border-radius:6px;font-size:13px;width:100%;display:flex;align-items:center;gap:8px}
.ctx-item:hover{background:var(--bg3)}
.ctx-item svg{flex-shrink:0}

/* Emoji picker */
#emojiPicker{position:fixed;z-index:210;background:var(--bg2);border-radius:12px;padding:10px;display:none;flex-wrap:wrap;gap:4px;width:220px;box-shadow:var(--shadow)}
.emoji-btn{background:none;border:none;font-size:22px;cursor:pointer;padding:4px 6px;border-radius:6px}
.emoji-btn:hover{background:var(--bg3)}

/* Members list */
.member-item{display:flex;align-items:center;gap:10px;padding:8px 0;border-bottom:1px solid var(--border)}
.member-avatar{width:36px;height:36px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:13px;font-weight:700;color:#fff;flex-shrink:0;position:relative}
.member-online-dot{position:absolute;bottom:1px;right:1px;width:9px;height:9px;border-radius:50%;background:var(--success);border:2px solid var(--bg2)}
.member-info{flex:1}
.member-name{font-size:14px;font-weight:600}
.member-role{font-size:11px;color:var(--t3)}

/* Search results */
.search-result-item{padding:10px;cursor:pointer;border-bottom:1px solid var(--border);border-radius:8px}
.search-result-item:hover{background:var(--bg3)}
.search-result-room{font-size:11px;color:var(--accent);margin-bottom:2px}
.search-result-text{font-size:13px;color:var(--t1)}
.search-result-time{font-size:10px;color:var(--t3);margin-top:2px}
.search-highlight{background:rgba(43,156,242,.3);border-radius:2px}

/* Media grid */
.media-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:3px}
.media-thumb{aspect-ratio:1;object-fit:cover;border-radius:4px;cursor:pointer;width:100%;display:block}
.media-file-item{display:flex;align-items:center;gap:10px;padding:10px;border-bottom:1px solid var(--border);cursor:pointer}
.media-file-item:hover{background:var(--bg3)}

/* QR display */
#qrDisplayCanvas{border-radius:10px;display:block;margin:0 auto}

/* Call overlay */
#callOverlay{position:fixed;inset:0;z-index:300;background:rgba(0,0,0,.9);display:none;flex-direction:column;align-items:center;justify-content:center;gap:20px;color:#fff}
#callOverlay.active{display:flex}
.call-avatar{width:80px;height:80px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:28px;font-weight:700;color:#fff;margin:0 auto}
.call-name{font-size:20px;font-weight:700;text-align:center}
.call-status{font-size:14px;color:rgba(255,255,255,.7);text-align:center}
.call-btns{display:flex;gap:24px;margin-top:20px}
.call-btn{width:64px;height:64px;border-radius:50%;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center}
.call-btn-accept{background:#4ade80;color:#fff}
.call-btn-reject{background:#f87171;color:#fff}
.call-btn-end{background:#f87171;color:#fff}
.call-btn-mute{background:rgba(255,255,255,.2);color:#fff}
.call-btn-mute.muted{background:rgba(255,255,255,.5)}
@keyframes ring{0%,100%{transform:scale(1)}50%{transform:scale(1.08)}}
#callOverlay.ringing .call-avatar{animation:ring .7s infinite}

/* PIN lock */
#pinScreen{position:fixed;inset:0;z-index:400;background:var(--bg);display:none;flex-direction:column;align-items:center;justify-content:center;gap:20px}
#pinScreen.active{display:flex}
.pin-dots{display:flex;gap:12px}
.pin-dot{width:14px;height:14px;border-radius:50%;background:var(--border);transition:background .15s}
.pin-dot.filled{background:var(--accent)}
.pin-pad{display:grid;grid-template-columns:repeat(3,64px);gap:10px}
.pin-key{height:64px;border-radius:50%;border:none;background:var(--bg2);color:var(--t1);font-size:20px;font-weight:600;cursor:pointer;transition:background .1s;font-family:inherit}
.pin-key:active{background:var(--accent);color:#fff}
.pin-key.del{font-size:14px}

/* Forward modal */
.fwd-room-item{display:flex;align-items:center;gap:10px;padding:10px;cursor:pointer;border-radius:8px}
.fwd-room-item:hover{background:var(--bg3)}

/* ══ MOBILE ═════════════════════════════════════════════ */
@media(max-width:680px){
  #sidebar{position:fixed;inset:0;z-index:10;width:100%;transition:transform .25s}
  #sidebar.hidden{transform:translateX(-100%)}
  #chatArea{width:100%}
  .chat-hdr-back{display:flex}
  .msg-bubble{max-width:85%}
}

/* Upload progress */
.upload-progress{position:fixed;bottom:0;left:0;right:0;z-index:100;background:var(--bg3);padding:8px 14px;display:flex;align-items:center;gap:10px;transform:translateY(100%);transition:transform .2s}
.upload-progress.show{transform:none}
.upload-bar-wrap{flex:1;height:4px;background:var(--border);border-radius:2px;overflow:hidden}
.upload-bar-fill{height:100%;background:var(--accent);border-radius:2px;transition:width .1s}

/* ══ CALL SETTINGS ══════════════════════════════════════ */
.proto-item{
  display:flex;flex-direction:column;gap:4px;
  padding:10px 12px;border:1px solid var(--border);border-radius:10px;
  margin-bottom:8px;background:var(--bg4);cursor:grab;
  transition:background .15s;
}
.proto-item:active{cursor:grabbing;background:var(--bg3)}
.proto-item[dragover]{border-color:var(--accent)}
.proto-drag-handle{font-size:16px;color:var(--t3);user-select:none;margin-right:4px}
.proto-toggle{display:flex;align-items:center;gap:8px;cursor:pointer}
.proto-toggle input[type=checkbox]{width:16px;height:16px;accent-color:var(--accent);cursor:pointer}
.proto-name{font-size:13px;font-weight:600}

.settings-section{font-size:11px;font-weight:600;color:var(--t3);text-transform:uppercase;letter-spacing:.6px;margin:16px 0 8px}
.settings-group{background:var(--bg4);border-radius:10px;padding:12px;display:flex;flex-direction:column;gap:10px;margin-bottom:12px}
.settings-row{display:flex;flex-direction:column;gap:4px}
.settings-row label{font-size:11px;color:var(--t3)}
.settings-row input,.settings-row select{
  background:var(--bg3);border:1px solid var(--border);border-radius:6px;
  color:var(--t1);font-size:13px;padding:7px 10px;outline:none;font-family:inherit;width:100%;
}
.settings-row input:focus,.settings-row select:focus{border-color:var(--accent)}

.proto-status-badge{
  display:inline-flex;align-items:center;gap:6px;
  font-size:11px;background:var(--bg3);border-radius:20px;
  padding:3px 10px;white-space:nowrap;
}
.proto-status-dot{width:7px;height:7px;border-radius:50%;background:var(--success);flex-shrink:0}
.proto-status-dot.warn{background:var(--warn)}
.proto-status-dot.err{background:var(--danger)}

/* Call overlay improvements */
#callProtoLabel{font-size:11px;color:rgba(255,255,255,.6);text-align:center;min-height:16px}
#callQuality{display:flex;gap:3px;align-items:center;justify-content:center}
.quality-bar{width:4px;border-radius:2px;background:rgba(255,255,255,.2)}
.quality-bar.active{background:#4ade80}

/* Swipe to reply */
.msg-swipe-icon{position:absolute;display:flex;align-items:center;color:var(--accent);opacity:0;transition:opacity .15s;pointer-events:none}
.msg-row.out .msg-swipe-icon{left:-28px}
.msg-row.in .msg-swipe-icon{right:-28px}
.msg-row.swipe-show .msg-swipe-icon{opacity:1}

/* ══ ME PANEL (bottom of sidebar) ═══════════════════════ */
.me-panel{
  padding:10px 12px;display:flex;align-items:center;gap:10px;
  border-top:1px solid var(--border);cursor:pointer;
  background:var(--bg2);transition:background .1s;flex-shrink:0;
}
.me-panel:hover{background:var(--bg3)}
.me-avatar{
  width:36px;height:36px;border-radius:50%;flex-shrink:0;
  display:flex;align-items:center;justify-content:center;
  font-size:14px;font-weight:700;color:#fff;position:relative;
  background-size:cover;background-position:center;
}
.me-avatar .status-ring{
  position:absolute;bottom:0;right:0;width:11px;height:11px;
  border-radius:50%;border:2px solid var(--bg2);
}
.me-info{flex:1;overflow:hidden}
.me-name{font-size:13px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.me-status{font-size:11px;color:var(--t3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* ══ PROFILE SETTINGS MODAL ══════════════════════════════ */
.profile-modal-box{max-width:460px;max-height:92vh;display:flex;flex-direction:column}
.profile-scroll{overflow-y:auto;padding:0 20px 16px;flex:1}
.profile-hero{display:flex;align-items:center;gap:16px;padding:20px 0 12px}
.profile-avatar-wrap{position:relative;cursor:pointer;flex-shrink:0}
.profile-avatar{
  width:72px;height:72px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  font-size:26px;font-weight:700;color:#fff;
  background-size:cover;background-position:center;
}
.profile-avatar-cam{
  position:absolute;bottom:0;right:0;width:24px;height:24px;border-radius:50%;
  background:var(--accent);display:flex;align-items:center;justify-content:center;
  color:#fff;border:2px solid var(--bg2);
}
.profile-hero-info{flex:1;overflow:hidden}
.profile-hero-name{font-size:17px;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.profile-hero-phone{font-size:13px;color:var(--t3);margin:2px 0 6px}
.profile-status-badge{
  display:inline-flex;align-items:center;gap:6px;font-size:12px;
  background:var(--bg3);border-radius:20px;padding:3px 10px;cursor:pointer;
  border:none;color:var(--t1);font-family:inherit;
}
.profile-status-badge:hover{background:var(--bg4)}
.profile-section-label{
  font-size:11px;font-weight:600;color:var(--accent);
  text-transform:uppercase;letter-spacing:.6px;margin:16px 0 8px;
}

/* Status styles */
.status-dot{display:inline-block;width:9px;height:9px;border-radius:50%;flex-shrink:0}
.s-online   {background:#4ade80}
.s-away     {background:#fbbf24}
.s-busy     {background:#f87171}
.s-dnd      {background:#a855f7}
.s-invisible{background:var(--t3)}
.status-grid{display:grid;grid-template-columns:1fr 1fr;gap:6px;margin-bottom:4px}
.status-opt{
  display:flex;align-items:center;gap:8px;padding:8px 10px;border-radius:10px;
  background:var(--bg3);border:1.5px solid transparent;color:var(--t1);
  font-size:13px;font-family:inherit;cursor:pointer;text-align:left;
  transition:border-color .15s,background .15s;
}
.status-opt:hover{background:var(--bg4)}
.status-opt.active{border-color:var(--accent);background:var(--bg4)}
.status-picker .settings-row input{font-size:13px;padding:8px 10px}

/* Toggle switch */
.toggle-row{justify-content:space-between;align-items:center;padding:10px 0}
.toggle-label{font-size:14px;font-weight:500}
.toggle-sub{font-size:12px;color:var(--t3);margin-top:2px}
.toggle-sw{position:relative;display:inline-block;width:42px;height:24px;flex-shrink:0}
.toggle-sw input{opacity:0;width:0;height:0}
.toggle-track{
  position:absolute;inset:0;border-radius:12px;background:var(--bg4);
  border:1px solid var(--border);cursor:pointer;transition:background .2s;
}
.toggle-track::after{
  content:'';position:absolute;top:3px;left:3px;width:16px;height:16px;
  border-radius:50%;background:#fff;transition:transform .2s;
}
.toggle-sw input:checked+.toggle-track{background:var(--accent);border-color:var(--accent)}
.toggle-sw input:checked+.toggle-track::after{transform:translateX(18px)}

/* Segmented control */
.seg-ctrl{display:flex;border-radius:8px;overflow:hidden;border:1px solid var(--border);background:var(--bg4)}
.seg-btn{
  flex:1;padding:6px 8px;border:none;background:transparent;color:var(--t2);
  font-size:13px;cursor:pointer;font-family:inherit;transition:background .15s,color .15s;
}
.seg-btn.active{background:var(--accent);color:#fff}

/* Room avatar status ring */
.room-avatar .status-ring{
  position:absolute;bottom:0px;right:0px;width:12px;height:12px;
  border-radius:50%;border:2px solid var(--bg2);
}

/* Font sizes applied to chat */
[data-fontsize="small"]  .msg-text{font-size:13px}
[data-fontsize="medium"] .msg-text{font-size:15px}
[data-fontsize="large"]  .msg-text{font-size:17px}

/* ── Push notification in-app banner ───────────────────────── */
.push-banner{
  position:fixed;top:12px;left:50%;transform:translateX(-50%);
  max-width:340px;width:calc(100% - 32px);
  background:var(--bg2);border:1px solid var(--border);
  border-radius:14px;padding:12px 16px;
  box-shadow:0 4px 20px rgba(0,0,0,.35);
  z-index:9999;cursor:pointer;
  animation:pushSlideIn .25s ease;
}
.push-banner-title{font-weight:600;font-size:14px;margin-bottom:2px;color:var(--text)}
.push-banner-body{font-size:13px;color:var(--text2);overflow:hidden;
  white-space:nowrap;text-overflow:ellipsis}
@keyframes pushSlideIn{from{opacity:0;transform:translateX(-50%) translateY(-12px)}
  to{opacity:1;transform:translateX(-50%) translateY(0)}}


/* ══ MOUNT POINT BADGE ══════════════════════════════════ */
.room-mount-badge{
  display:inline-flex;align-items:center;font:500 9.5px/1 'IBM Plex Mono',monospace;
  letter-spacing:.04em;padding:3px 6px;border-radius:5px;
  background:rgba(255,255,255,.06);color:rgba(232,236,239,.55);
  flex-shrink:0;white-space:nowrap;
}
[data-theme="light"] .room-mount-badge{background:rgba(0,0,0,.07);color:rgba(15,19,24,.55)}

/* Status pulse dot in chat header and room list */
@keyframes pulseDot{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.55;transform:scale(.85)}}
.status-pulse{display:inline-block;width:6px;height:6px;border-radius:50%;background:var(--success);animation:pulseDot 2.4s infinite;flex-shrink:0}

/* ══ MONO HELPERS ═══════════════════════════════════════ */
.mono{font-family:'IBM Plex Mono',ui-monospace,monospace}
.room-time{font-family:'IBM Plex Mono',ui-monospace,monospace}
.msg-time,.msg-edited{font-family:'IBM Plex Mono',ui-monospace,monospace}

/* Sidebar search — mono placeholder */
.sidebar-search input{font-family:'IBM Plex Mono',ui-monospace,monospace;font-size:12px}

/* ══ BOTTOM TAB BAR (mobile only) ══════════════════════ */
@media(max-width:680px){
  #bottomTabBar{display:block !important}
  #sidebar{display:flex;flex-direction:column}
  .room-list{flex:1;min-height:0;overflow-y:auto}
  /* Sidebar header — hide desktop controls, keep new chat */
  .sidebar-hdr .icon-btn:not(#searchBtn):not(:last-of-type){display:none}
  /* Avatar in sidebar header becomes compact */
  #sidebar .sidebar-hdr{padding:8px 12px;background:var(--bg-bar);border-bottom:1px solid var(--border)}
  #sidebar .sidebar-search{background:var(--bg-bar)}
}
