/* =========================================================
   TELEGRAM-STYLE DARK THEME
   ========================================================= */
:root {
  --tg-bg:        #0e1621;
  --tg-bg2:       #17212b;
  --tg-bg3:       #242f3d;
  --tg-bg4:       #2b3847;
  --tg-accent:    #2aabee;
  --tg-accent-h:  #1a96d4;
  --tg-text:      #e8f1f8;
  --tg-text2:     #7d8b99;
  --tg-text3:     #4e5d6c;
  --tg-danger:    #e55353;
  --tg-success:   #49ae2b;
  --tg-div:       rgba(255,255,255,0.06);
  --tg-hover:     rgba(255,255,255,0.04);
  --tg-bubble-out:#2b5278;
  --tg-bubble-in: #182533;
  --tg-online:    #49ae2b;

  /* Legacy compat */
  --accent:         var(--tg-accent);
  --danger:         var(--tg-danger);
  --success:        var(--tg-success);
  --text-primary:   var(--tg-text);
  --text-secondary: var(--tg-text2);
  --bg-primary:     var(--tg-bg);
  --bg-secondary:   var(--tg-bg2);
  --glass-bg:       var(--tg-bg2);
  --glass-border:   var(--tg-div);
  --msg-mine-bg:    var(--tg-bubble-out);
  --msg-other-bg:   var(--tg-bubble-in);
  --scrollbar-thumb:var(--tg-bg4);
}

/* =========================================================
   BASE
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, textarea { font-family: inherit; }

::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--tg-bg4); border-radius: 99px; }

#app {
  position: fixed;
  inset: 0;
  height: var(--app-height, 100vh);
  overflow: hidden;
  background: var(--tg-bg);
}

/* =========================================================
   SCREENS
   ========================================================= */
.tg-screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--tg-bg);
}
.tg-screen.active { display: flex; }

/* =========================================================
   TOAST
   ========================================================= */
#copy-toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--tg-bg3);
  color: var(--tg-text);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 9999;
  white-space: nowrap;
}
#copy-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =========================================================
   ACCOUNT SCREEN
   ========================================================= */
#account-screen {
  overflow-y: auto;
  justify-content: center;
  align-items: center;
  padding: 20px 20px env(safe-area-inset-bottom);
}
.tg-auth-wrap {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tg-auth-logo { color: var(--tg-accent); margin-bottom: 16px; }
.tg-auth-title { font-size: 1.8rem; font-weight: 700; margin-bottom: 6px; text-align: center; }
.tg-auth-sub   { font-size: 0.9rem; color: var(--tg-text2); text-align: center; margin-bottom: 28px; }

.tg-auth-tabs {
  display: flex;
  width: 100%;
  background: var(--tg-bg2);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
}
.tg-auth-tab {
  flex: 1;
  padding: 9px;
  border-radius: 9px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--tg-text2);
  transition: background 0.2s, color 0.2s;
}
.tg-auth-tab.active, .tg-auth-tab.tab-active {
  background: var(--tg-bg3);
  color: var(--tg-text);
}

.tg-auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Inputs */
.tg-auth-form input,
.tg-modal-sheet input,
.tg-edit-nick input,
#message-input {
  width: 100%;
  -webkit-user-select: text;
  user-select: text;
}
.tg-auth-form input,
.tg-modal-sheet input,
.tg-edit-nick input {
  padding: 13px 16px;
  border-radius: 10px;
  background: var(--tg-bg2);
  border: 1px solid transparent;
  color: var(--tg-text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
.tg-auth-form input:focus,
.tg-modal-sheet input:focus,
.tg-edit-nick input:focus { border-color: var(--tg-accent); }
.tg-auth-form input::placeholder,
.tg-modal-sheet input::placeholder,
.tg-edit-nick input::placeholder { color: var(--tg-text3); }

.tg-btn-primary {
  width: 100%;
  padding: 13px;
  border-radius: 10px;
  background: var(--tg-accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  transition: background 0.2s, opacity 0.2s;
  margin-top: 4px;
}
.tg-btn-primary:hover   { background: var(--tg-accent-h); }
.tg-btn-primary:active  { opacity: 0.85; }
.tg-btn-primary:disabled{ opacity: 0.5; }

.tg-btn-ghost {
  width: 100%;
  padding: 11px;
  border-radius: 10px;
  background: transparent;
  color: var(--tg-text2);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid var(--tg-div);
  transition: background 0.2s;
}
.tg-btn-ghost:hover  { background: var(--tg-hover); }
.tg-btn-ghost:active { background: var(--tg-bg3); }

.tg-error-msg {
  font-size: 0.82rem;
  color: var(--tg-danger);
  min-height: 16px;
  text-align: center;
}
.tg-accent { color: var(--tg-accent); }

/* =========================================================
   MAIN SCREEN — TOPBAR
   ========================================================= */
.tg-topbar {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 8px 0 12px;
  padding-top: env(safe-area-inset-top);
  background: var(--tg-bg2);
  border-bottom: 1px solid var(--tg-div);
  flex-shrink: 0;
}
.tg-topbar-avatar-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.tg-topbar-avatar-btn:hover { background: var(--tg-hover); }
.tg-topbar-title { flex: 1; font-size: 1.1rem; font-weight: 700; padding: 0 8px; }
.tg-topbar-icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--tg-accent);
  transition: background 0.15s;
}
.tg-topbar-icon-btn:hover  { background: rgba(42,171,238,0.1); }
.tg-topbar-icon-btn:active { background: rgba(42,171,238,0.2); }

.tg-avatar-sm {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--tg-accent);
  color: #fff;
  font-size: 0.8rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; text-transform: uppercase;
}

/* =========================================================
   MAIN SCREEN — CHAT LIST
   ========================================================= */
.tg-chat-list-wrap {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#my-rooms-section { display: block; }
#my-rooms-list    { display: flex; flex-direction: column; }

.tg-chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--tg-div);
  cursor: pointer;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.tg-chat-item:hover  { background: var(--tg-hover); }
.tg-chat-item:active { background: var(--tg-bg3); }

.tg-chat-item-avatar {
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--tg-accent);
  color: #fff;
  font-size: 1.2rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; text-transform: uppercase;
}

.tg-chat-item-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 3px;
}
.tg-chat-item-row1 { display: flex; align-items: center; gap: 6px; }
.tg-chat-item-name {
  flex: 1;
  font-size: 0.97rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tg-chat-item-time { font-size: 0.75rem; color: var(--tg-text2); flex-shrink: 0; }
.tg-chat-item-row2 { display: flex; align-items: center; gap: 6px; }
.tg-chat-item-preview {
  flex: 1;
  font-size: 0.85rem; color: var(--tg-text2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tg-chat-item-del {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--tg-text3);
  font-size: 1rem; flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.tg-chat-item-del:hover { background: rgba(229,83,83,0.15); color: var(--tg-danger); }

.tg-empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  padding: 60px 32px;
  color: var(--tg-text3); text-align: center;
}
.tg-empty-state p    { font-size: 1rem; color: var(--tg-text2); }
.tg-empty-sub        { font-size: 0.85rem !important; color: var(--tg-text3) !important; }

/* =========================================================
   MAIN SCREEN — JOIN MODAL
   ========================================================= */
.tg-modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: flex-end; justify-content: center;
}
.tg-modal-overlay.open { display: flex; }

.tg-modal-sheet {
  width: 100%; max-width: 500px;
  background: var(--tg-bg2);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px max(32px,env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
  animation: slideUp 0.3s cubic-bezier(0.32,0.72,0,1);
}
.tg-modal-handle {
  width: 36px; height: 4px;
  border-radius: 2px; background: var(--tg-bg4);
  margin: 0 auto 8px;
}
.tg-modal-title {
  font-size: 1.1rem; font-weight: 700; text-align: center; margin-bottom: 4px;
}
.tg-modal-hint { font-size: 0.8rem; color: var(--tg-text2); text-align: center; }
.tg-modal-hint a { color: var(--tg-accent); text-decoration: none; }

/* =========================================================
   MAIN SCREEN — BOTTOM NAV
   ========================================================= */
.tg-bottom-nav {
  display: flex;
  height: calc(56px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--tg-bg2);
  border-top: 1px solid var(--tg-div);
  flex-shrink: 0;
}
.tg-nav-item {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  color: var(--tg-text3);
  font-size: 0.65rem; font-weight: 500;
  transition: color 0.15s;
  padding: 6px 4px;
}
.tg-nav-item svg { opacity: 0.5; }
.tg-nav-item:active { color: var(--tg-accent); }
.tg-nav-active { color: var(--tg-accent) !important; }
.tg-nav-active svg { opacity: 1; stroke: var(--tg-accent); }

/* =========================================================
   CHAT SCREEN — HEADER
   ========================================================= */
.tg-chat-header {
  display: flex; align-items: center;
  height: 56px; padding: 0 4px;
  padding-top: env(safe-area-inset-top);
  background: var(--tg-bg2);
  border-bottom: 1px solid var(--tg-div);
  flex-shrink: 0; gap: 2px;
}
.tg-chat-back-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--tg-accent);
  transition: background 0.15s; flex-shrink: 0;
}
.tg-chat-back-btn:hover  { background: rgba(42,171,238,0.1); }
.tg-chat-back-btn:active { background: rgba(42,171,238,0.2); }

.tg-chat-header-center {
  flex: 1; display: flex; align-items: center; gap: 10px;
  min-width: 0; padding: 4px 6px; border-radius: 10px;
  text-align: left; transition: background 0.15s;
}
.tg-chat-header-center:hover  { background: var(--tg-hover); }
.tg-chat-header-center:active { background: var(--tg-bg3); }

.tg-avatar-md {
  width: 40px; height: 40px;
  border-radius: 50%; background: var(--tg-accent);
  color: #fff; font-size: 0.95rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; text-transform: uppercase;
}
.tg-chat-header-text { min-width: 0; }
.tg-chat-name {
  font-size: 0.97rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tg-chat-sub { font-size: 0.75rem; color: var(--tg-accent); }

.tg-chat-header-btns { display: flex; align-items: center; flex-shrink: 0; }
.tg-chat-icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--tg-text2); transition: background 0.15s;
}
.tg-chat-icon-btn:hover  { background: var(--tg-hover); }
.tg-chat-icon-btn:active { background: var(--tg-bg3); }

/* =========================================================
   CHAT SCREEN — MESSAGES
   ========================================================= */
#messages-container {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 8px 0;
  display: flex; flex-direction: column; gap: 2px;
  min-height: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--tg-bg);
}
#messages-container::-webkit-scrollbar { width: 3px; }
#messages-container::-webkit-scrollbar-thumb { background: var(--tg-bg4); }

.message-group {
  display: flex; flex-direction: column;
  max-width: 76%; padding: 0 10px; gap: 2px;
}
.message-group.mine  { align-self: flex-end;  align-items: flex-end; }
.message-group.other { align-self: flex-start; align-items: flex-start; }

.message-sender {
  font-size: 0.78rem; font-weight: 600;
  color: var(--tg-accent); margin-bottom: 2px; padding: 0 4px;
}

.message-bubble {
  padding: 7px 10px 22px;
  border-radius: 14px;
  position: relative;
  font-size: 0.93rem; line-height: 1.45;
  word-break: break-word;
  -webkit-user-select: text; user-select: text;
}
.message-bubble.mine {
  background: var(--tg-bubble-out); color: #e8f1f8;
  border-bottom-right-radius: 4px;
}
.message-bubble.other {
  background: var(--tg-bubble-in); color: #e8f1f8;
  border-bottom-left-radius: 4px;
}

.message-time {
  position: absolute; bottom: 4px; right: 8px;
  font-size: 0.68rem; color: rgba(232,241,248,0.55);
  white-space: nowrap;
}

/* Animation */
.message-enter { animation: msgIn 0.2s ease; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0   rgba(229,83,83,0.5); }
  70%  { box-shadow: 0 0 0 18px rgba(229,83,83,0); }
  100% { box-shadow: 0 0 0 0   rgba(229,83,83,0); }
}

/* =========================================================
   VOICE PLAYER
   ========================================================= */
.voice-message {
  display: flex; align-items: center; gap: 10px;
  min-width: 200px; max-width: 280px;
}
.voice-play-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,0.15); color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.15s;
}
.voice-play-btn:hover { background: rgba(255,255,255,0.25); }
.voice-progress-wrapper { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.voice-waveform { height: 3px; background: rgba(255,255,255,0.2); border-radius: 2px; overflow: hidden; }
.voice-waveform-fill { height: 100%; width: 0%; background: rgba(255,255,255,0.7); border-radius: 2px; transition: width 0.1s linear; }
.voice-duration { font-size: 0.72rem; color: rgba(255,255,255,0.6); }

/* =========================================================
   VIDEO MESSAGE
   ========================================================= */
.video-message { position: relative; cursor: pointer; border-radius: 12px; overflow: hidden; max-width: 240px; }
.video-message video { display: block; max-width: 240px; max-height: 240px; border-radius: 12px; object-fit: cover; }
.video-play-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.3); border-radius: 12px; }
.video-play-circle { width: 48px; height: 48px; border-radius: 50%; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; color: #fff; }

/* =========================================================
   INPUT AREA
   ========================================================= */
#input-area {
  display: flex; align-items: center; gap: 6px;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--tg-bg2);
  border-top: 1px solid var(--tg-div);
  flex-shrink: 0; min-height: 58px;
  position: relative;
}
.tg-input-icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--tg-text2); flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.tg-input-icon-btn:hover  { background: var(--tg-hover); color: var(--tg-accent); }
.tg-input-icon-btn:active { color: var(--tg-accent); }

.tg-input-wrap {
  flex: 1; background: var(--tg-bg3);
  border-radius: 22px;
  display: flex; align-items: center;
  min-height: 40px; padding: 0 14px;
}
.tg-input-wrap input,
#message-input {
  border: none; background: transparent;
  color: var(--tg-text); font-size: 0.95rem;
  outline: none; padding: 0;
  -webkit-user-select: text; user-select: text;
}
#message-input::placeholder { color: var(--tg-text3); }

.tg-send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--tg-accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.15s, transform 0.1s;
}
.tg-send-btn:hover  { background: var(--tg-accent-h); }
.tg-send-btn:active { transform: scale(0.92); }

.tg-emoji-picker {
  position: absolute; bottom: 60px; left: 8px;
  background: var(--tg-bg2); border: 1px solid var(--tg-div);
  border-radius: 14px; padding: 10px;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
  z-index: 20; box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.tg-emoji-btn { background: none; font-size: 1.3rem; padding: 5px; border-radius: 8px; cursor: pointer; transition: background 0.1s; }
.tg-emoji-btn:hover { background: var(--tg-bg3); }

/* =========================================================
   INFO DRAWER (SIDEBAR)
   ========================================================= */
#sidebar.tg-drawer {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 100%; max-width: 360px;
  background: var(--tg-bg2);
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  z-index: 10;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
#sidebar.tg-drawer.open { transform: translateX(0); }

.tg-drawer-header {
  display: flex; align-items: center;
  height: 56px; padding: 0 8px;
  padding-top: env(safe-area-inset-top);
  background: var(--tg-bg2);
  border-bottom: 1px solid var(--tg-div);
  flex-shrink: 0; gap: 6px;
}
.tg-drawer-title { font-size: 1rem; font-weight: 700; flex: 1; }

.tg-profile-card {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--tg-div); flex-shrink: 0;
}
.tg-avatar-lg {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--tg-accent); color: #fff;
  font-size: 1.3rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; text-transform: uppercase;
}
.tg-profile-info { flex: 1; min-width: 0; }
.tg-profile-name { font-size: 0.97rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-profile-uname { font-size: 0.8rem; color: var(--tg-text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tg-icon-btn-sm {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--tg-text2); flex-shrink: 0; transition: background 0.15s;
}
.tg-icon-btn-sm:hover { background: var(--tg-hover); }

.tg-edit-nick {
  padding: 12px 20px; border-bottom: 1px solid var(--tg-div);
  display: flex; flex-direction: column; gap: 8px;
}
.tg-edit-nick-row { display: flex; gap: 8px; }
.tg-edit-nick-row .tg-btn-primary { flex: 1; padding: 10px; }
.tg-edit-nick-row .tg-btn-ghost   { width: auto; padding: 10px 14px; }

.tg-drawer-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--tg-div);
}
.tg-drawer-label { font-size: 0.8rem; color: var(--tg-text2); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; }
.tg-drawer-val-row { display: flex; align-items: center; gap: 6px; }
.tg-room-id { font-family: 'Consolas', monospace; font-size: 0.82rem; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tg-drawer-actions { display: flex; flex-direction: column; border-bottom: 1px solid var(--tg-div); }
.tg-drawer-btn {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px; font-size: 0.93rem; color: var(--tg-text);
  transition: background 0.12s; width: 100%; text-align: left;
}
.tg-drawer-btn:hover  { background: var(--tg-hover); }
.tg-drawer-btn:active { background: var(--tg-bg3); }
.tg-drawer-btn-danger { color: var(--tg-danger); }
.tg-drawer-btn-danger svg { stroke: var(--tg-danger); }

.tg-section-label {
  font-size: 0.75rem; font-weight: 600; color: var(--tg-text2);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 12px 20px 6px;
}
.tg-participants-list { display: flex; flex-direction: column; padding-bottom: 20px; }

.participant-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; transition: background 0.12s;
}
.participant-item:hover { background: var(--tg-hover); }
.participant-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--tg-bg4); color: var(--tg-text2);
  font-size: 0.9rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.participant-online { width: 8px; height: 8px; border-radius: 50%; background: var(--tg-online); margin-left: auto; flex-shrink: 0; }

/* =========================================================
   RECORDER SCREEN
   ========================================================= */
#recorder-screen {
  display: none; position: fixed; inset: 0; z-index: 50;
  background: rgba(10,14,22,0.95);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  flex-direction: column; align-items: center; justify-content: center;
  gap: 24px; padding: 32px 20px;
}
#recorder-screen.active { display: flex; }

#recorder-close-btn {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.8);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
#recorder-close-btn:hover { background: rgba(255,255,255,0.2); }

#recorder-type { font-size: 1.1rem; font-weight: 600; color: var(--tg-text); }
#recorder-timer { font-size: 3.5rem; font-weight: 700; font-family: 'Consolas', monospace; color: var(--tg-text); letter-spacing: 0.05em; }

#video-preview {
  display: none; width: 100%; max-width: 380px;
  aspect-ratio: 4/3; max-height: 285px; border-radius: 16px;
  background: #000; object-fit: cover;
}
#video-preview.active { display: block; }

#wave-canvas {
  width: 100%; max-width: 400px; height: 80px;
  border-radius: 12px; background: rgba(42,171,238,0.06);
  border: 1px solid rgba(42,171,238,0.15);
}

#recorder-main-controls {
  display: flex; align-items: center; justify-content: center; gap: 28px;
}

#record-toggle-btn {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--tg-danger); color: #fff;
  border: 4px solid rgba(229,83,83,0.3);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.15s;
  animation: pulse 2s infinite;
}
#record-toggle-btn.stopped {
  background: var(--tg-accent); border-color: rgba(42,171,238,0.3); animation: none;
}
#record-toggle-btn.preview {
  background: var(--tg-danger); border-color: rgba(229,83,83,0.4); animation: pulse 2s infinite;
}
#record-toggle-btn:hover  { transform: scale(1.06); }
#record-toggle-btn:active { transform: scale(0.95); }

#switch-camera-btn, #pause-resume-btn {
  display: none; width: 56px; height: 56px; border-radius: 50%;
  background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.9);
  border: 2px solid rgba(255,255,255,0.2);
  align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.15s;
}
#switch-camera-btn.active, #pause-resume-btn.active { display: flex; }
#switch-camera-btn:hover, #pause-resume-btn:hover { background: rgba(255,255,255,0.22); }
#switch-camera-btn:active, #pause-resume-btn:active { transform: scale(0.92); }

.recorder-actions { display: flex; gap: 16px; }

#send-media-btn, #discard-media-btn {
  display: none; padding: 11px 26px;
  font-size: 0.95rem; font-weight: 600;
  border-radius: 10px; align-items: center; gap: 6px;
}
#send-media-btn.visible, #discard-media-btn.visible { display: inline-flex; }
#send-media-btn    { background: var(--tg-success); color: #fff; }
#discard-media-btn { background: var(--tg-danger);  color: #fff; }
#send-media-btn:hover    { background: #39922e; }
#discard-media-btn:hover { background: #c0392b; }

/* =========================================================
   LEGACY COMPAT
   ========================================================= */
.btn-accent {
  background: var(--tg-accent); color: #fff; border: none;
  border-radius: 10px; padding: 10px 20px; font-size: 0.9rem; font-weight: 600;
}
.btn-accent:hover { background: var(--tg-accent-h); }
.btn-danger { background: var(--tg-danger); color: #fff; border: none; border-radius: 10px; padding: 10px 20px; }
.btn-ghost  { background: var(--tg-bg3); color: var(--tg-text2); border: none; border-radius: 10px; padding: 10px 20px; }
.glass { background: var(--tg-bg2); border: 1px solid var(--tg-div); border-radius: 16px; }

@media (min-width: 768px) {
  #sidebar.tg-drawer {
    width: 320px;
  }
}
