/* ═══ KFOO Chat - Midnight Pulse Design ═══ */
:root {
  --surface: #131313;
  --surface-low: #1c1b1b;
  --surface-lowest: #0e0e0e;
  --surface-high: #2a2a2a;
  --surface-highest: #353534;
  --surface-bright: #3a3939;
  --primary: #d0bcff;
  --primary-container: #a078ff;
  --on-primary: #3c0091;
  --secondary-container: #474747;
  --on-surface: #e5e2e1;
  --on-surface-variant: #cbc3d7;
  --outline-variant: #494454;
  --danger: #ff6b6b;
  --success: #6bffb8;
  --font-display: 'Cairo', 'Plus Jakarta Sans', sans-serif;
  --font-body: 'Cairo', 'Inter', sans-serif;
  --radius-sm: .25rem;
  --radius-md: .75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;
  --transition: .2s ease-in-out;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--on-surface);
  min-height: 100vh;
  overflow: hidden;
  direction: rtl;
}
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--outline-variant); border-radius: var(--radius-full); }
.hidden { display: none !important; }
button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }
input, textarea { font-family: inherit; color: var(--on-surface); background: var(--surface-highest); border: none; outline: none; padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .95rem; transition: var(--transition); }
input:focus, textarea:focus { background: var(--surface-bright); box-shadow: 0 0 0 1px rgba(73,68,84,.2); }
a { color: var(--primary); text-decoration: none; }

/* ═══ BUTTONS ═══ */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: var(--on-primary);
  padding: .75rem 1.5rem;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: .95rem;
  display: inline-flex; align-items: center; gap: .5rem;
  transition: var(--transition);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 30px rgba(160,120,255,.25); }
.btn-primary svg { width: 18px; height: 18px; }
.btn-full { width: 100%; justify-content: center; }
.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full);
  transition: var(--transition);
  flex-shrink: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: rgba(208,188,255,.1); }
.icon-btn.danger:hover { background: rgba(255,107,107,.15); color: var(--danger); }

/* ═══ AUTH SCREEN ═══ */
.auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
  z-index: 1000;
}
.auth-bg-orbs { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.orb {
  position: absolute; border-radius: 50%;
  filter: blur(100px); opacity: .3;
  animation: orbFloat 8s ease-in-out infinite alternate;
}
.orb-1 { width: 400px; height: 400px; background: var(--primary-container); top: -100px; right: -100px; }
.orb-2 { width: 300px; height: 300px; background: #6b3fa0; bottom: -80px; left: -80px; animation-delay: 2s; }
.orb-3 { width: 200px; height: 200px; background: var(--primary); top: 50%; left: 50%; animation-delay: 4s; }
@keyframes orbFloat { to { transform: translate(40px, -30px) scale(1.1); } }

.auth-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 420px;
  padding: 2.5rem 2rem;
  border-radius: var(--radius-xl);
  animation: fadeSlideUp .6s ease;
}
@keyframes fadeSlideUp { from { opacity: 0; transform: translateY(30px); } }
.glass {
  background: rgba(28,27,27,.7);
  backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px);
  border: 1px solid rgba(73,68,84,.15);
}
.auth-logo { text-align: center; margin-bottom: .5rem; display: flex; align-items: center; justify-content: center; gap: .75rem; }
.logo-img { height: 48px; border-radius: var(--radius-md); }
.logo-text { font-family: var(--font-display); font-size: 2rem; font-weight: 800; background: linear-gradient(135deg, var(--primary), var(--primary-container)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.auth-tagline { text-align: center; color: var(--on-surface-variant); margin-bottom: 1.5rem; font-size: .9rem; }
.auth-tabs { display: flex; gap: .5rem; margin-bottom: 1.5rem; background: var(--surface-lowest); border-radius: var(--radius-full); padding: 4px; }
.auth-tab { flex: 1; padding: .6rem; border-radius: var(--radius-full); font-weight: 600; font-size: .9rem; transition: var(--transition); color: var(--on-surface-variant); }
.auth-tab.active { background: linear-gradient(135deg, var(--primary), var(--primary-container)); color: var(--on-primary); }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.field-group { display: flex; flex-direction: column; gap: .4rem; }
.field-group label { font-size: .85rem; color: var(--on-surface-variant); font-weight: 500; }
.auth-error { color: var(--danger); font-size: .85rem; min-height: 1.2em; }
.btn-loader { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ APP LAYOUT ═══ */
.app { display: flex; height: 100vh; width: 100vw; }

/* ═══ SIDEBAR ═══ */
.sidebar {
  width: 340px; min-width: 340px;
  background: var(--surface-low);
  display: flex; flex-direction: column;
  transition: var(--transition);
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
}
.sidebar-logo { display: flex; align-items: center; gap: .5rem; font-family: var(--font-display); font-size: 1.3rem; font-weight: 800; }
.logo-sm { height: 32px; border-radius: var(--radius-sm); }
.header-actions { display: flex; gap: .25rem; }
.sidebar-search {
  margin: 0 1rem .75rem;
  display: flex; align-items: center; gap: .5rem;
  background: var(--surface-highest);
  padding: 0 .75rem;
  border-radius: var(--radius-sm);
}
.sidebar-search svg { width: 18px; height: 18px; color: var(--on-surface-variant); flex-shrink: 0; }
.sidebar-search input { background: transparent; padding: .65rem 0; flex: 1; font-size: .9rem; }
.sidebar-search input:focus { background: transparent; box-shadow: none; }

/* ═══ CONVERSATION LIST ═══ */
.conv-list { flex: 1; overflow-y: auto; padding: 0 .5rem; }
.conv-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .85rem .75rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}
.conv-item:hover { background: var(--surface-high); }
.conv-item.active { background: var(--surface-high); }
.conv-item .avatar { flex-shrink: 0; }
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: .95rem; margin-bottom: .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-last { font-size: .82rem; color: var(--on-surface-variant); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; flex-shrink: 0; }
.conv-time { font-size: .75rem; color: var(--on-surface-variant); }
.conv-badge {
  background: var(--primary-container);
  color: var(--on-primary);
  font-size: .7rem; font-weight: 700;
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full);
}
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem 1rem; color: var(--on-surface-variant); text-align: center; }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 1rem; opacity: .4; }
.empty-state p { font-weight: 600; margin-bottom: .25rem; }
.empty-state small { font-size: .8rem; opacity: .6; }

/* ═══ SIDEBAR FOOTER ═══ */
.sidebar-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem;
  background: var(--surface-lowest);
}
.user-profile-mini { display: flex; align-items: center; gap: .75rem; cursor: pointer; flex: 1; padding: .35rem; border-radius: var(--radius-md); transition: var(--transition); }
.user-profile-mini:hover { background: var(--surface-high); }
.avatar-wrap { position: relative; }
.avatar {
  width: 42px; height: 42px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: var(--on-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.status-dot {
  position: absolute; bottom: 0; left: 0;
  width: 12px; height: 12px;
  border-radius: var(--radius-full);
  border: 2px solid var(--surface-low);
  background: var(--outline-variant);
}
.status-dot.online { background: var(--success); }
.user-name-mini { font-weight: 600; font-size: .9rem; }
.user-uid-mini { font-size: .75rem; color: var(--on-surface-variant); }

/* ═══ CHAT AREA ═══ */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--surface); position: relative; min-width: 0; }

/* Welcome */
.welcome-screen { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.welcome-orbs { position: absolute; inset: 0; pointer-events: none; }
.orb-sm-1 { width: 200px; height: 200px; background: var(--primary-container); top: 20%; right: 10%; opacity: .15; filter: blur(80px); }
.orb-sm-2 { width: 150px; height: 150px; background: #6b3fa0; bottom: 20%; left: 15%; opacity: .1; filter: blur(60px); animation-delay: 3s; }
.welcome-content { text-align: center; z-index: 1; animation: fadeSlideUp .8s ease; }
.welcome-logo { height: 80px; margin-bottom: 1.5rem; border-radius: var(--radius-lg); }
.welcome-content h1 { font-family: var(--font-display); font-size: 1.8rem; font-weight: 800; margin-bottom: .5rem; }
.welcome-content p { color: var(--on-surface-variant); margin-bottom: 1.5rem; }

/* Chat View */
.chat-view { display: flex; flex-direction: column; flex: 1; height: 100%; }

.chat-header {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1.25rem;
  background: rgba(28,27,27,.8);
  backdrop-filter: blur(20px);
  z-index: 10;
}
.back-btn { display: none; }
.chat-header-info { display: flex; align-items: center; gap: .75rem; flex: 1; cursor: pointer; padding: .25rem .5rem; border-radius: var(--radius-md); transition: var(--transition); }
.chat-header-info:hover { background: rgba(255,255,255,.04); }
.chat-name { font-weight: 700; font-size: 1rem; }
.chat-sub { font-size: .8rem; color: var(--on-surface-variant); }
.chat-actions { display: flex; gap: .25rem; }

/* Messages */
.messages-area { flex: 1; overflow-y: auto; padding: 1rem; }
.messages-wrap { display: flex; flex-direction: column; gap: .5rem; max-width: 900px; margin: 0 auto; }
.msg-row { display: flex; gap: .5rem; animation: msgIn .3s ease; }
.msg-row.sent { flex-direction: row-reverse; }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px); } }
.msg-avatar { flex-shrink: 0; }
.msg-avatar .avatar { width: 32px; height: 32px; font-size: .75rem; }
/* Avatar spacer keeps alignment for grouped messages (no visible avatar) */
.msg-avatar-spacer { flex-shrink: 0; width: 32px; }
/* Grouped messages: tighter spacing, sharper corners */
.msg-row.grouped { animation: none; }
.msg-row.grouped .msg-bubble { border-bottom-right-radius: var(--radius-lg); }
.msg-row.grouped.sent .msg-bubble { border-bottom-left-radius: var(--radius-lg); border-bottom-right-radius: var(--radius-sm); }
.msg-row.grouped .msg-bubble { padding-top: .45rem; padding-bottom: .45rem; }
.msg-row.grouped .msg-time { display: none; }
.msg-bubble {
  max-width: 65%;
  padding: .65rem 1rem;
  border-radius: var(--radius-lg);
  font-size: .93rem;
  line-height: 1.55;
  position: relative;
}
.msg-row:not(.sent) .msg-bubble { background: var(--surface-high); border-bottom-right-radius: var(--radius-sm); }
.msg-row.sent .msg-bubble { background: linear-gradient(135deg, var(--primary), var(--primary-container)); color: var(--on-primary); border-bottom-left-radius: var(--radius-sm); }
.msg-sender { font-size: .78rem; font-weight: 600; color: var(--primary); margin-bottom: .2rem; }
.msg-time { font-size: .7rem; opacity: .6; margin-top: .25rem; text-align: left; }
.msg-row.sent .msg-time { text-align: right; }
.msg-date-divider { text-align: center; padding: 1rem 0; }
.msg-date-divider span { background: var(--surface-high); padding: .35rem 1rem; border-radius: var(--radius-full); font-size: .78rem; color: var(--on-surface-variant); }

/* Chat Input */
.chat-input-area {
  display: flex; align-items: flex-end; gap: .5rem;
  padding: .75rem 1rem;
  background: var(--surface-low);
}
.input-wrap { flex: 1; }
.input-wrap textarea {
  width: 100%;
  background: var(--surface-highest);
  border-radius: var(--radius-lg);
  padding: .75rem 1rem;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  font-size: .93rem;
}
.btn-send {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: var(--on-primary);
  border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-send:hover { transform: scale(1.05); }
.btn-send svg { width: 20px; height: 20px; }
.attach-btn { margin-bottom: 2px; }

/* ═══ INFO PANEL ═══ */
.info-panel {
  width: 320px; min-width: 320px;
  background: var(--surface-high);
  display: flex; flex-direction: column;
  overflow-y: auto;
  animation: slideInLeft .3s ease;
}
@keyframes slideInLeft { from { transform: translateX(-20px); opacity: 0; } }
.info-panel-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; }
.info-panel-header h3 { font-family: var(--font-display); font-weight: 700; }
.info-panel-content { padding: 0 1.25rem 1.25rem; }
.info-profile { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 1.5rem 0; }
.info-avatar { width: 80px; height: 80px; font-size: 2rem; margin-bottom: .75rem; }
.info-name { font-weight: 700; font-size: 1.1rem; margin-bottom: .2rem; }
.info-uid { color: var(--on-surface-variant); font-size: .85rem; }
.info-section { margin-top: 1.5rem; }
.info-section h4 { font-size: .85rem; color: var(--on-surface-variant); margin-bottom: .75rem; font-weight: 600; }
.member-item { display: flex; align-items: center; gap: .65rem; padding: .5rem 0; }
.member-item .avatar { width: 36px; height: 36px; font-size: .8rem; }
.member-name { font-weight: 500; font-size: .9rem; }
.member-role { font-size: .75rem; color: var(--primary); }

/* ═══ MODALS ═══ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  width: 90%; max-width: 440px;
  padding: 2rem;
  border-radius: var(--radius-xl);
  animation: fadeSlideUp .3s ease;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.modal-header h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; }
.modal-body { display: flex; flex-direction: column; gap: 1rem; }
.search-row { display: flex; gap: .5rem; }
.search-row input { flex: 1; }
.search-result-area { min-height: 60px; }
.search-result-card {
  display: flex; align-items: center; gap: 1rem;
  background: var(--surface-highest);
  padding: 1rem;
  border-radius: var(--radius-md);
  animation: fadeSlideUp .3s ease;
}
.search-result-card .avatar { width: 48px; height: 48px; }
.search-result-info { flex: 1; }
.search-result-info .name { font-weight: 700; }
.search-result-info .uid { font-size: .82rem; color: var(--on-surface-variant); }
.profile-avatar-big {
  width: 80px; height: 80px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: var(--on-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700;
  margin: 0 auto 1rem;
}
.uid-badge { text-align: center; color: var(--primary); font-size: .9rem; margin-bottom: 1rem; font-weight: 600; }

/* ═══ MESSAGE MEDIA ═══ */
.msg-image { margin: .25rem 0; }
.msg-image img {
  max-width: 280px; max-height: 300px;
  border-radius: var(--radius-md);
  cursor: pointer; transition: transform .2s;
  display: block;
}
.msg-image img:hover { transform: scale(1.03); }
.msg-file {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem; border-radius: var(--radius-md);
  background: rgba(208,188,255,.1); cursor: pointer;
  transition: background .2s; min-width: 200px;
}
.msg-file:hover { background: rgba(208,188,255,.2); }
.msg-file-icon {
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.msg-file-icon svg { width: 20px; height: 20px; }
.msg-file-info { flex: 1; min-width: 0; }
.msg-file-name { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-file-ext { font-size: .75rem; color: var(--on-surface-variant); }
.msg-image-broken {
  padding: 1.25rem; text-align: center;
  background: rgba(255, 107, 107, .1);
  border-radius: var(--radius-md);
  color: var(--on-surface-variant);
  font-size: .85rem;
}
.attach-btn.uploading { animation: uploadPulse 1s infinite; pointer-events: none; opacity: .6; }
@keyframes uploadPulse { 50% { transform: scale(1.2); } }

/* Image Preview Overlay */
.image-preview-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.9); backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; animation: fadeIn .2s;
}
.image-preview-full { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: var(--radius-md); }
.image-preview-close {
  position: absolute; top: 1.5rem; right: 1.5rem;
  font-size: 2.5rem; color: #fff; cursor: pointer;
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.15); border-radius: 50%;
  transition: background .2s;
}
.image-preview-close:hover { background: rgba(255,255,255,.3); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ═══ CALL OVERLAY ═══ */
.call-overlay {
  position: fixed; inset: 0;
  z-index: 900;
  display: flex; flex-direction: column;
  transition: all .3s cubic-bezier(.34, 1.2, .64, 1);
}

/* DESKTOP: floating portrait window in bottom-right (only on real desktop, landscape ≥ 1024px) */
@media (min-width: 1024px) and (orientation: landscape) {
  .call-overlay:not(.call-fullscreen) {
    top: auto; left: auto;
    bottom: 20px; right: 20px;
    width: 380px;
    height: min(640px, calc(100vh - 40px));
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .08);
    z-index: 950;
  }
  .call-overlay:not(.call-fullscreen) .call-bg-blur { border-radius: 24px; }
  .call-overlay:not(.call-fullscreen) .local-video {
    width: 90px; height: 120px;
    bottom: 100px; left: 14px;
    border: 2px solid rgba(255,255,255,.15);
  }
  .call-overlay:not(.call-fullscreen) .big-avatar { width: 80px; height: 80px; font-size: 2rem; }
  .call-overlay:not(.call-fullscreen) .call-name-display { font-size: 1rem; }
  .call-overlay:not(.call-fullscreen) .call-controls {
    gap: .55rem;
    padding: .85rem .65rem 1.1rem;
    flex-wrap: wrap;
  }
  .call-overlay:not(.call-fullscreen) .call-btn { width: 44px; height: 44px; }
  .call-overlay:not(.call-fullscreen) .call-btn svg { width: 20px; height: 20px; }
  .call-overlay:not(.call-fullscreen) .call-btn.danger { width: 50px; height: 50px; }
  .call-overlay:not(.call-fullscreen) .call-btn.danger svg { width: 22px; height: 22px; }
  .call-overlay:not(.call-fullscreen) .call-status-bar { padding: .5rem; }
  .call-overlay:not(.call-fullscreen) .call-timer { font-size: .9rem; }
  .call-overlay:not(.call-fullscreen) .call-status-text { font-size: .8rem; }
  .call-overlay:not(.call-fullscreen) .viewer-controls,
  .call-overlay:not(.call-fullscreen) .screen-share-controls {
    bottom: .75rem; padding: .4rem .65rem; gap: .35rem;
  }
  .call-overlay:not(.call-fullscreen) .ss-ctrl-btn { width: 34px; height: 34px; }
  .call-overlay:not(.call-fullscreen) .ss-ctrl-btn svg { width: 16px; height: 16px; }
  .call-overlay:not(.call-fullscreen) .ss-stop-btn span { display: none; }
}

.call-bg-blur { position: absolute; inset: 0; background: rgba(14,14,14,.95); backdrop-filter: blur(40px); }
.call-container { position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; }
.video-area { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.remote-video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.local-video { position: absolute; bottom: 100px; left: 20px; width: 180px; height: 135px; object-fit: cover; border-radius: var(--radius-lg); z-index: 10; }
.no-video-placeholder { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.big-avatar { width: 120px; height: 120px; border-radius: var(--radius-full); background: linear-gradient(135deg, var(--primary), var(--primary-container)); color: var(--on-primary); display: flex; align-items: center; justify-content: center; font-size: 3rem; font-weight: 700; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); box-shadow: 0 0 40px rgba(160,120,255,.3); } }
.call-name-display { font-size: 1.3rem; font-weight: 700; }
.call-status-bar { text-align: center; padding: .75rem; }
.call-status-text { font-size: .9rem; color: var(--on-surface-variant); }
.call-timer { font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.call-controls { display: flex; justify-content: center; gap: 1.25rem; padding: 1.5rem; }
.call-btn {
  width: 56px; height: 56px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,.12);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  transition: all .2s ease; position: relative;
}
.call-btn svg { width: 24px; height: 24px; color: #fff; }
.call-btn:hover { background: rgba(255,255,255,.22); transform: scale(1.08); }
.call-btn.danger { background: #ff3b30; color: #fff; width: 64px; height: 64px; }
.call-btn.danger svg { width: 28px; height: 28px; }
.call-btn.danger:hover { background: #ff5544; transform: scale(1.1); }
.call-btn.success { background: #34c759; color: #fff; }
.call-btn.success:hover { background: #40d86a; }
.call-btn.active {
  background: rgba(255,59,48,.85); color: #fff;
}
.call-btn.active svg { color: #fff; }
.call-btn.active:hover { background: rgba(255,59,48,1); }
.screen-share-area { position: absolute; inset: 0; z-index: 5; }
/* Viewer Controls - shown for the person WATCHING a screen share */
.viewer-controls {
  position: absolute; bottom: 2rem; left: 50%; transform: translateX(-50%);
  z-index: 15;
  display: flex; align-items: center; gap: .75rem;
  background: rgba(0,0,0,.6); backdrop-filter: blur(20px);
  padding: .75rem 1.25rem; border-radius: var(--radius-full);
  border: 1px solid rgba(255,255,255,.1);
}
.screen-video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.screen-share-badge { position: absolute; top: 1rem; right: 1rem; background: rgba(208,188,255,.2); backdrop-filter: blur(10px); padding: .5rem 1rem; border-radius: var(--radius-full); font-size: .85rem; display: flex; align-items: center; gap: .5rem; }
.screen-share-badge svg { width: 16px; height: 16px; }

/* Screen Share Floating Controls */
.screen-share-controls {
  position: absolute; bottom: 2rem; left: 50%; transform: translateX(-50%);
  z-index: 10;
  display: flex; align-items: center; gap: .75rem;
  background: rgba(0,0,0,.6); backdrop-filter: blur(20px);
  padding: .75rem 1.25rem; border-radius: var(--radius-full);
  border: 1px solid rgba(255,255,255,.1);
}
.ss-ctrl-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.15); border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .2s ease;
}
.ss-ctrl-btn svg { width: 20px; height: 20px; }
.ss-ctrl-btn:hover { background: rgba(255,255,255,.3); transform: scale(1.1); }
.ss-ctrl-btn.ss-muted { background: rgba(255,59,48,.85); }
.ss-ctrl-btn.ss-muted:hover { background: rgba(255,59,48,1); }
.ss-end-btn { background: #ff3b30; }
.ss-end-btn:hover { background: #ff5544 !important; }
.ss-stop-btn {
  width: auto; border-radius: var(--radius-full);
  padding: 0 1rem; gap: .5rem; font-size: .85rem; font-weight: 600;
  background: rgba(255,59,48,.85);
}
.ss-stop-btn span { white-space: nowrap; }
.ss-stop-btn:hover { background: rgba(255,59,48,1) !important; }

/* Incoming Call */
.incoming-call-modal { text-align: center; padding: 2.5rem; }
.incoming-call-avatar { width: 100px; height: 100px; border-radius: var(--radius-full); background: linear-gradient(135deg, var(--primary), var(--primary-container)); color: var(--on-primary); display: flex; align-items: center; justify-content: center; font-size: 2.5rem; font-weight: 700; margin: 0 auto 1rem; animation: pulse 2s ease-in-out infinite; }
.incoming-call-name { font-size: 1.3rem; font-weight: 700; margin-bottom: .25rem; }
.incoming-group-name {
  font-size: .9rem; color: var(--primary);
  margin-bottom: .35rem; font-weight: 600;
}
.incoming-call-type { color: var(--on-surface-variant); font-size: .9rem; margin-bottom: 1.5rem; }
.incoming-call-actions { display: flex; justify-content: center; gap: 2rem; }

/* Call Top Bar */
.call-top-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: flex-start; gap: .5rem; padding: 1rem;
}
.call-minimize-btn, .call-fullscreen-btn {
  background: rgba(255,255,255,.12);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-full);
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
}
.call-minimize-btn svg, .call-fullscreen-btn svg { width: 20px; height: 20px; }
.call-minimize-btn:hover, .call-fullscreen-btn:hover { background: rgba(255,255,255,.25); }

/* ═══════════════════════════════════════════════════════════════
   TELEGRAM-STYLE GROUP CALL WINDOW
   ═══════════════════════════════════════════════════════════════ */
.group-call-overlay {
  position: fixed; inset: 0;
  z-index: 9700;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.group-call-overlay > * { pointer-events: auto; }
.gc-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(8px);
  animation: fadeIn .25s ease;
}
.gc-window {
  position: relative; z-index: 1;
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  background: #1e1e1e;
  border-radius: 20px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, .7);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: gcSlideIn .35s cubic-bezier(.34, 1.4, .64, 1);
  border: 1px solid rgba(255, 255, 255, .06);
}
@keyframes gcSlideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ─── Header ─── */
.gc-header {
  display: flex; align-items: center; gap: .5rem;
  padding: .9rem 1rem;
  background: linear-gradient(180deg, #2a2a2a, #1e1e1e);
  border-bottom: 1px solid rgba(255, 255, 255, .04);
}
.gc-header-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, .75);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.gc-header-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.gc-header-btn svg { width: 18px; height: 18px; }
.gc-title-block { flex: 1; min-width: 0; text-align: center; }
.gc-title-name {
  font-weight: 700; font-size: 1.05rem; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gc-title-meta {
  font-size: .8rem; color: rgba(255, 255, 255, .55);
  margin-top: 2px;
}

/* ─── Video stage (when camera/screen is active) ─── */
.gc-video-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  max-height: 50vh;
  background: #000;
  overflow: hidden;
  flex-shrink: 0;
}
.gc-main-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}
.gc-stage-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: #000;
  color: rgba(255,255,255,.6);
  font-size: .9rem;
  gap: .75rem;
  text-align: center; padding: 1rem;
}
.gc-stage-empty-icon { font-size: 3rem; opacity: .5; }
.gc-pip-video {
  position: absolute;
  bottom: 12px;
  left: 12px;
  width: 90px;
  height: 120px;
  border-radius: 10px;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.2);
  background: #1a1a1a;
  z-index: 5;
  box-shadow: 0 4px 15px rgba(0,0,0,.4);
}
.gc-stage-info {
  position: absolute;
  bottom: 12px; right: 12px;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  padding: 5px 12px;
  border-radius: 8px;
  color: #fff;
  font-size: .82rem;
  font-weight: 600;
  z-index: 4;
}
/* When stage is visible, expand the window for better video viewing */
.gc-window:has(.gc-video-stage:not(.hidden)) {
  width: 520px;
}
@media (min-width: 1024px) {
  .gc-window:has(.gc-video-stage:not(.hidden)) {
    width: 720px;
  }
}

/* ─── Body: participants list ─── */
.gc-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: #1e1e1e;
  min-height: 140px;
  max-height: 50vh;
}
/* When video stage is visible, body is smaller (just participant list) */
.gc-window:has(.gc-video-stage:not(.hidden)) .gc-body {
  max-height: 32vh;
  min-height: 100px;
}
.gc-participants {
  background: #2a2a2a;
  border-radius: 14px;
  padding: .35rem;
  margin-bottom: .75rem;
}
.gc-participant {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem .75rem;
  border-radius: 10px;
  transition: var(--transition);
}
.gc-participant:hover { background: rgba(255, 255, 255, .03); }
.gc-participant-avatar {
  position: relative;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: var(--on-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1rem;
  flex-shrink: 0;
  overflow: hidden;
}
.gc-participant-info {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
}
.gc-participant-name {
  font-weight: 600; font-size: .92rem; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gc-participant-name .gc-self-tag {
  font-size: .7rem; color: var(--primary); margin-right: 4px;
}
.gc-participant-status {
  font-size: .75rem; color: rgba(255, 255, 255, .5);
  display: flex; align-items: center; gap: 4px;
}
.gc-participant-status.speaking { color: #34c759; }
.gc-participant-status.connecting { color: var(--primary); }
.gc-participant-mic {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  color: rgba(255, 255, 255, .55);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.gc-participant-mic svg { width: 14px; height: 14px; }
.gc-participant-mic.muted { color: #ff6b6b; background: rgba(255, 107, 107, .12); }
.gc-participant-avatar-ring {
  position: absolute; inset: -3px;
  border-radius: 50%;
  border: 2px solid transparent;
}
.gc-participant.is-speaking .gc-participant-avatar-ring {
  border-color: #34c759;
  animation: gcSpeakPulse 1.2s ease-in-out infinite;
}
@keyframes gcSpeakPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 199, 89, .55); }
  50% { box-shadow: 0 0 0 6px rgba(52, 199, 89, 0); }
}

/* ─── Invite button ─── */
.gc-invite-btn {
  width: 100%;
  display: flex; align-items: center; gap: .75rem;
  padding: .9rem 1rem;
  background: #2a2a2a;
  border: none;
  border-radius: 12px;
  color: var(--primary);
  font-size: .92rem; font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.gc-invite-btn:hover { background: #333; }
.gc-invite-icon {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(208, 188, 255, .15);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.gc-invite-icon svg { width: 20px; height: 20px; }

/* ─── Bottom action bar ─── */
.gc-actions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .35rem;
  padding: .85rem 1rem 1.1rem;
  background: linear-gradient(180deg, #1e1e1e, #181818);
  border-top: 1px solid rgba(255, 255, 255, .04);
}
.gc-action {
  display: flex; flex-direction: column;
  align-items: center;
  gap: .35rem;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: .25rem;
  border-radius: 12px;
  transition: var(--transition);
  color: rgba(255, 255, 255, .85);
}
.gc-action:hover { background: rgba(255, 255, 255, .04); }
.gc-action span {
  font-size: .72rem;
  white-space: nowrap;
}
.gc-action-icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  color: #fff;
}
.gc-action-icon svg { width: 20px; height: 20px; }
.gc-action:hover .gc-action-icon { background: rgba(255, 255, 255, .15); }
.gc-action.active .gc-action-icon { background: var(--primary); color: var(--on-primary); }

/* Mute mic button — main, larger */
.gc-action.gc-mic-main .gc-action-icon {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: var(--on-primary);
  box-shadow: 0 4px 18px rgba(208, 188, 255, .35);
}
.gc-action.gc-mic-main.muted .gc-action-icon {
  background: linear-gradient(135deg, #ff6b6b, #ff3b30);
  color: #fff;
  box-shadow: 0 4px 18px rgba(255, 59, 48, .4);
}
.gc-action.gc-mic-main .gc-action-icon svg { width: 24px; height: 24px; }
.gc-action.gc-mic-main span { font-weight: 700; color: #fff; }

/* Leave button */
.gc-action.gc-leave-action .gc-action-icon {
  background: #ff3b30; color: #fff;
}
.gc-action.gc-leave-action:hover .gc-action-icon { background: #ff5544; }
.gc-action.gc-leave-action span { color: #ff6b6b; font-weight: 700; }

/* Mobile fullscreen */
@media (max-width: 768px) {
  .gc-window {
    width: 100% !important;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  .gc-body { max-height: none; flex: 1; }
  /* When video stage active on mobile: stage takes most of screen, participants compress below */
  .gc-video-stage {
    aspect-ratio: unset;
    height: 45vh;
    max-height: 50vh;
  }
  .gc-window:has(.gc-video-stage:not(.hidden)) .gc-body {
    max-height: none;
    flex: 0 0 auto;
    max-height: 25vh;
  }
  .gc-pip-video {
    width: 75px;
    height: 105px;
    bottom: 10px;
    left: 10px;
  }
  .gc-actions { padding-bottom: max(1.1rem, env(safe-area-inset-bottom)); }
  .gc-header { padding-top: max(.9rem, env(safe-area-inset-top)); }
}

/* Mini Call Bar — Telegram-style prominent top bar */
.mini-call-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9500;
  min-height: 56px;
  background: linear-gradient(90deg, #34c759, #28a745);
  display: flex; align-items: center; justify-content: space-between;
  padding: .5rem 1rem;
  cursor: pointer;
  animation: miniCallSlideIn .35s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 4px 20px rgba(52, 199, 89, .35);
  user-select: none;
}
.mini-call-bar:hover { background: linear-gradient(90deg, #3dd166, #2ab14d); box-shadow: 0 6px 25px rgba(52, 199, 89, .5); }
.mini-call-bar:active { transform: scale(.99); }
@keyframes miniCallSlideIn { from { transform: translateY(-100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.mini-call-info { display: flex; align-items: center; gap: .75rem; flex: 1; min-width: 0; }
.mini-call-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 0 rgba(255,255,255,.7);
  animation: miniCallPulse 1.5s infinite;
  flex-shrink: 0;
}
@keyframes miniCallPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,.7); }
  50% { box-shadow: 0 0 0 6px rgba(255,255,255,0); }
}
.mini-call-text {
  display: flex; flex-direction: column;
  min-width: 0; flex: 1;
}
.mini-call-name {
  font-size: .95rem; font-weight: 700; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mini-call-hint {
  font-size: .7rem; color: rgba(255,255,255,.85);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mini-call-timer {
  font-size: .9rem; color: rgba(255,255,255,.95);
  font-variant-numeric: tabular-nums; font-weight: 600;
  background: rgba(255,255,255,.15); padding: .25rem .6rem;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.mini-call-actions { display: flex; gap: .5rem; flex-shrink: 0; }
.mini-call-end {
  background: rgba(255,59,48,.95); border: none; color: #fff;
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition);
}
.mini-call-end svg { width: 18px; height: 18px; }
.mini-call-end:hover { background: #ff3b30; transform: scale(1.1); }
.mini-call-mic {
  background: rgba(255,255,255,.25); border: none; color: #fff;
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition);
}
.mini-call-mic svg { width: 18px; height: 18px; }
.mini-call-mic:hover { background: rgba(255,255,255,.4); transform: scale(1.1); }
.mini-call-mic.mini-muted { background: #ff3b30; }
.mini-call-mic.mini-muted:hover { background: #ff5544; }

/* Body class pushes whole app down when mini call bar is shown */
body.has-mini-call .app { padding-top: 56px; }
body.has-mini-call .sidebar { padding-top: 56px; }

/* ═══ TOAST ═══ */
.toast-container { position: fixed; top: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--surface-high);
  backdrop-filter: blur(20px);
  padding: .75rem 1.5rem;
  border-radius: var(--radius-full);
  font-size: .9rem;
  animation: toastIn .3s ease, toastOut .3s ease 2.7s forwards;
  white-space: nowrap;
  border: 1px solid rgba(73,68,84,.15);
}
.toast.success { border-color: rgba(107,255,184,.3); }
.toast.error { border-color: rgba(255,107,107,.3); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-20px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-20px); } }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  .sidebar { position: fixed; inset: 0; z-index: 100; width: 100%; min-width: unset; transform: translateX(0); }
  .sidebar.sidebar-hidden { transform: translateX(100%); }
  .info-panel { position: fixed; inset: 0; z-index: 200; width: 100%; min-width: unset; }
  .back-btn { display: flex; }
  .chat-area { position: fixed; inset: 0; z-index: 50; }

  /* ─── CALL OVERLAY: optimize for portrait phone screens ─── */
  .call-overlay {
    z-index: 9900;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border-radius: 0 !important;
  }
  .call-bg-blur { border-radius: 0 !important; }
  .call-top-bar { padding: .75rem; gap: .4rem; }
  .call-minimize-btn, .call-fullscreen-btn { width: 40px; height: 40px; }
  .call-minimize-btn svg, .call-fullscreen-btn svg { width: 18px; height: 18px; }
  /* Hide fullscreen button on mobile (always fullscreen there) */
  .call-fullscreen-btn { display: none; }

  .local-video {
    width: 100px; height: 135px;
    bottom: 100px; left: 12px;
    border: 2px solid rgba(255,255,255,.18);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(0,0,0,.5);
  }
  .big-avatar { width: 90px; height: 90px; font-size: 2.2rem; }
  .call-name-display {
    font-size: 1rem;
    max-width: 80vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    padding: 0 1rem;
  }
  .no-video-placeholder { padding: 0 1rem; }
  .call-status-bar { padding: .5rem; }
  .call-timer { font-size: 1rem; }
  .call-controls {
    gap: .55rem; padding: 1rem .65rem 1.25rem;
    flex-wrap: wrap; justify-content: center;
  }
  .call-btn { width: 48px; height: 48px; }
  .call-btn svg { width: 20px; height: 20px; }
  .call-btn.danger { width: 54px; height: 54px; }
  .call-btn.danger svg { width: 22px; height: 22px; }

  /* ─── CHAT HEADER: avoid overflow with email-like names ─── */
  .chat-header { padding: .65rem .75rem; gap: .5rem; }
  .chat-header-info { min-width: 0; flex: 1; }
  .chat-header-info > div { min-width: 0; flex: 1; }
  .chat-name {
    font-size: .92rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 100%;
  }
  .chat-sub { font-size: .72rem; }
  .chat-actions { gap: .15rem; flex-shrink: 0; }
  .chat-actions .icon-btn { width: 36px; height: 36px; }
  .chat-actions .icon-btn svg { width: 18px; height: 18px; }
  /* Hide info button on mobile (less clutter — accessible via header tap) */
  .chat-actions #btn-info { display: none; }

  /* ─── CHAT MESSAGES: tighter spacing on mobile ─── */
  .messages-wrap { padding: .65rem .5rem; gap: .15rem; }
  .msg-bubble { max-width: 78vw; }
  .msg-image img { max-width: 70vw; max-height: 60vw; }

  /* Incoming call modal - tighten for phone */
  .incoming-call-modal { padding: 2rem 1.25rem; }
  .incoming-call-avatar { width: 80px; height: 80px; font-size: 2rem; }
  .incoming-call-name { font-size: 1.1rem; }
  .incoming-call-actions { gap: 1.5rem; }

  /* Mini call bar — slightly tighter */
  .mini-call-bar { min-height: 52px; padding: .4rem .75rem; }
  .mini-call-name { font-size: .88rem; }
  .mini-call-hint { font-size: .65rem; }
  .mini-call-timer { font-size: .82rem; padding: .2rem .5rem; }
  .mini-call-end, .mini-call-mic { width: 34px; height: 34px; }
  .mini-call-end svg, .mini-call-mic svg { width: 16px; height: 16px; }
  body.has-mini-call .app { padding-top: 52px; }
  body.has-mini-call .sidebar { padding-top: 52px; }

  /* Screen share area on mobile */
  .screen-share-area { z-index: 6; }
  .screen-share-controls, .viewer-controls {
    bottom: 1rem; padding: .5rem .85rem; gap: .5rem;
  }
  .ss-ctrl-btn { width: 38px; height: 38px; }
  .ss-ctrl-btn svg { width: 18px; height: 18px; }
  .ss-stop-btn { padding: 0 .75rem; font-size: .78rem; }
  .ss-stop-btn span { display: none; }
  .screen-share-badge { top: .75rem; right: .75rem; padding: .35rem .75rem; font-size: .75rem; }
}

/* ─── Landscape phones / tablets ─── */
@media (max-width: 768px) and (orientation: landscape) {
  .local-video {
    width: 130px; height: 90px;
    bottom: 80px;
  }
  .call-controls { padding: .5rem .75rem .75rem; }
  .call-btn { width: 44px; height: 44px; }
  .big-avatar { width: 70px; height: 70px; font-size: 1.8rem; }
}

/* ─── Larger phones / small tablets ─── */
@media (min-width: 480px) and (max-width: 768px) {
  .local-video { width: 130px; height: 175px; }
}

/* ─── iOS Safari notch / safe area support ─── */
@supports (padding: max(0px)) {
  .mini-call-bar { padding-top: max(.5rem, env(safe-area-inset-top)); min-height: calc(56px + env(safe-area-inset-top)); }
  body.has-mini-call .app { padding-top: calc(56px + env(safe-area-inset-top)); }
  body.has-mini-call .sidebar { padding-top: calc(56px + env(safe-area-inset-top)); }
  .call-top-bar { padding-top: max(1rem, env(safe-area-inset-top)); }
  .call-controls { padding-bottom: max(1.5rem, env(safe-area-inset-bottom)); }
}

/* ═══════════════════════════════════════════════════════════════
   GROUP MANAGEMENT UI
   ═══════════════════════════════════════════════════════════════ */

/* Privacy toggle on Create Group modal */
.privacy-toggle-group {
  display: flex; flex-direction: column; gap: .5rem;
  margin: .5rem 0;
}
.privacy-option {
  display: flex; align-items: center; gap: .85rem;
  padding: .85rem 1rem;
  background: var(--surface-highest);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  border: 2px solid transparent;
}
.privacy-option:hover { background: var(--surface-bright); }
.privacy-option.active {
  border-color: var(--primary);
  background: rgba(208, 188, 255, .08);
}
.privacy-icon { font-size: 1.5rem; flex-shrink: 0; }
.privacy-text { flex: 1; min-width: 0; }
.privacy-title { font-weight: 700; font-size: .92rem; margin-bottom: .15rem; }
.privacy-desc { font-size: .75rem; color: var(--on-surface-variant); }
.privacy-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--outline-variant);
  flex-shrink: 0;
  position: relative;
}
.privacy-option.active .privacy-check {
  border-color: var(--primary);
  background: var(--primary);
}
.privacy-option.active .privacy-check::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--on-primary);
  font-weight: 900;
  font-size: .8rem;
}

/* Group ID display — prominent, clickable */
.group-id-section { margin-top: .5rem; }
.group-id-display {
  display: flex; align-items: center; gap: .65rem;
  background: linear-gradient(135deg, rgba(208,188,255,.12), rgba(160,120,255,.08));
  padding: .85rem 1rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid rgba(208,188,255,.18);
}
.group-id-display:hover {
  background: linear-gradient(135deg, rgba(208,188,255,.18), rgba(160,120,255,.12));
  border-color: rgba(208,188,255,.35);
}
.group-id-display:active { transform: scale(.98); }
.group-id-icon { font-size: 1.3rem; flex-shrink: 0; }
.group-id-text {
  flex: 1;
  font-family: monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  direction: ltr;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.group-id-copy-hint {
  font-size: .7rem;
  color: var(--on-surface-variant);
  flex-shrink: 0;
}

/* Info panel — description */
.info-desc {
  background: var(--surface-low);
  padding: .85rem 1rem;
  border-radius: var(--radius-md);
  font-size: .88rem;
  line-height: 1.6;
  color: var(--on-surface-variant);
}

/* Privacy badge */
.privacy-badge {
  display: inline-flex; align-items: center;
  padding: .35rem .85rem;
  border-radius: var(--radius-full);
  font-size: .8rem;
  font-weight: 600;
}
.privacy-badge.public { background: rgba(107, 255, 184, .12); color: #6bffb8; }
.privacy-badge.private { background: rgba(208, 188, 255, .12); color: var(--primary); }

/* Invite link box */
.invite-link-box {
  display: flex; align-items: center; gap: .35rem;
  background: var(--surface-highest);
  border-radius: var(--radius-md);
  padding: .4rem;
}
.invite-link-box input {
  flex: 1; min-width: 0;
  background: transparent;
  padding: .4rem .65rem;
  font-size: .8rem;
  font-family: monospace;
  direction: ltr;
}
.invite-link-box input:focus { background: transparent; box-shadow: none; }
.invite-link-box .icon-btn {
  width: 36px; height: 36px;
  background: var(--primary);
  color: var(--on-primary);
}
.invite-link-box .icon-btn:hover { background: var(--primary-container); }
.invite-link-box .icon-btn svg { width: 16px; height: 16px; }

/* Switch toggle */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: .65rem 0;
  font-size: .9rem;
  cursor: pointer;
}
.switch {
  width: 44px; height: 24px;
  background: var(--surface-highest);
  border-radius: var(--radius-full);
  position: relative;
  transition: var(--transition);
  cursor: pointer;
  flex-shrink: 0;
}
.switch.on { background: var(--primary); }
.switch-knob {
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 3px;
  right: 3px;  /* RTL: knob starts on right when off */
  transition: transform .25s cubic-bezier(.34,1.56,.64,1);
}
.switch.on .switch-knob { transform: translateX(-20px); }  /* RTL: move left when on */

/* Tertiary button */
.btn-tertiary {
  background: var(--surface-high);
  color: var(--on-surface);
  padding: .65rem 1rem;
  border-radius: var(--radius-md);
  font-size: .85rem;
  font-weight: 600;
  transition: var(--transition);
}
.btn-tertiary:hover { background: var(--surface-bright); }
.btn-tertiary.full { width: 100%; display: block; margin-top: .5rem; }
.btn-tertiary.danger { color: var(--danger); }
.btn-tertiary.danger:hover { background: rgba(255, 107, 107, .1); }

/* Member item — enhanced with remove button */
.member-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .5rem 0;
}
.member-info { flex: 1; min-width: 0; }
.member-name {
  font-weight: 600; font-size: .9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.member-uid { font-size: .72rem; color: var(--on-surface-variant); }
.member-role { font-size: .72rem; color: var(--primary); font-weight: 600; }
.member-item .icon-btn { width: 32px; height: 32px; flex-shrink: 0; }
.member-item .icon-btn svg { width: 14px; height: 14px; }

/* Join Group confirmation card */
.join-group-card { text-align: center; padding: .5rem; }
.join-group-name {
  font-size: 1.3rem;
  font-weight: 800;
  font-family: var(--font-display);
  margin-top: 1rem;
  margin-bottom: .5rem;
}
.join-group-desc {
  color: var(--on-surface-variant);
  font-size: .9rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}
.join-group-meta {
  display: inline-block;
  background: var(--surface-highest);
  padding: .5rem 1rem;
  border-radius: var(--radius-full);
  font-size: .82rem;
  color: var(--on-surface-variant);
  margin-bottom: 1.5rem;
}

/* ═══════════════════════════════════════════════════════════════
   MINI BROADCAST BAR (when broadcaster minimizes)
   ═══════════════════════════════════════════════════════════════ */
@keyframes gsbSlideIn { from { transform: translateY(-100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ═══════════════════════════════════════════════════════════════
   IN-CHAT GROUP CALL BANNER (inside chat-view, below header)
   ═══════════════════════════════════════════════════════════════ */
.in-chat-call-banner {
  display: flex; align-items: center; gap: .65rem;
  padding: .65rem .9rem;
  background: linear-gradient(90deg, #34c759, #28a745);
  color: #fff;
  cursor: pointer;
  user-select: none;
  animation: iccbSlideIn .3s ease;
  box-shadow: 0 4px 15px rgba(52, 199, 89, .25);
  flex-shrink: 0;
}
@keyframes iccbSlideIn { from { transform: translateY(-12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.in-chat-call-banner:hover { background: linear-gradient(90deg, #3dd166, #2ab14d); }
.iccb-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1rem; color: #fff;
  flex-shrink: 0;
  animation: iccbAvatarPulse 1.6s ease-in-out infinite;
}
@keyframes iccbAvatarPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,.55); }
  50% { box-shadow: 0 0 0 8px rgba(255,255,255,0); }
}
.iccb-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.iccb-title {
  font-weight: 800; font-size: .92rem;
  display: flex; align-items: center; gap: .4rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.iccb-title svg { width: 16px; height: 16px; flex-shrink: 0; }
.iccb-hint {
  font-size: .72rem; opacity: .92;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.iccb-join {
  background: #fff;
  color: #1e7e34;
  border: none;
  padding: .5rem 1.25rem;
  border-radius: var(--radius-full);
  font-weight: 800; font-size: .85rem;
  cursor: pointer; flex-shrink: 0;
  transition: var(--transition);
  font-family: inherit;
}
.iccb-join:hover { transform: scale(1.05); box-shadow: 0 4px 15px rgba(255,255,255,.4); }
.iccb-dismiss {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,.2);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.iccb-dismiss:hover { background: rgba(0,0,0,.4); }
@media (max-width: 480px) {
  .in-chat-call-banner { padding: .5rem .65rem; gap: .5rem; }
  .iccb-avatar { width: 34px; height: 34px; font-size: .9rem; }
  .iccb-title { font-size: .85rem; }
  .iccb-hint { font-size: .68rem; }
  .iccb-join { padding: .45rem 1rem; font-size: .8rem; }
  .iccb-dismiss { width: 26px; height: 26px; }
}

/* ─── Active call indicator on conversation list item ─── */
.conv-item.has-call-pulse {
  background: linear-gradient(90deg, rgba(52,199,89,.08), transparent);
}
.conv-item.has-call-pulse:hover {
  background: linear-gradient(90deg, rgba(52,199,89,.15), var(--surface-high));
}
.conv-call-dot {
  position: absolute;
  bottom: -2px; left: -2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #34c759;
  border: 2px solid var(--surface-low);
  animation: convCallPulse 1.4s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(52, 199, 89, .7);
}
@keyframes convCallPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 199, 89, .7); }
  50% { box-shadow: 0 0 0 6px rgba(52, 199, 89, 0); }
}
.conv-call-preview {
  display: flex; align-items: center; gap: .35rem;
  color: #34c759;
  font-size: .8rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: convCallTextPulse 1.8s ease-in-out infinite;
}
@keyframes convCallTextPulse { 50% { opacity: .65; } }
.conv-call-preview svg { width: 14px; height: 14px; flex-shrink: 0; }

#mini-broadcast-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 9450;
  background: linear-gradient(90deg, #ff3b30, #d62828);
  color: #fff;
  padding-top: max(.5rem, env(safe-area-inset-top));
  box-shadow: 0 4px 25px rgba(255, 59, 48, .5);
  cursor: pointer;
  animation: gsbSlideIn .35s cubic-bezier(.34,1.56,.64,1);
  user-select: none;
}
.mini-bcb-inner {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem 1rem;
}
.mini-bcb-dot {
  width: 10px; height: 10px;
  background: #fff; border-radius: 50%;
  flex-shrink: 0;
  animation: gsbPulse2 1.5s ease-in-out infinite;
}
@keyframes gsbPulse2 {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,.7); }
  50% { box-shadow: 0 0 0 8px rgba(255,255,255,0); }
}
.mini-bcb-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mini-bcb-title {
  font-weight: 800; font-size: .92rem;
  white-space: nowrap;
}
.mini-bcb-hint {
  font-size: .72rem; opacity: .9;
  white-space: nowrap;
}
.mini-bcb-timer {
  background: rgba(255,255,255,.2);
  padding: .25rem .65rem;
  border-radius: var(--radius-full);
  font-size: .85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.mini-bcb-action {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.25);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}
.mini-bcb-action:hover { background: rgba(0,0,0,.45); transform: scale(1.08); }
.mini-bcb-action svg { width: 18px; height: 18px; }
.mini-bcb-end { background: rgba(0,0,0,.35); }

body.has-mini-broadcast .app { padding-top: 60px; }
body.has-mini-broadcast .sidebar { padding-top: 60px; }
@supports (padding: max(0px)) {
  body.has-mini-broadcast .app { padding-top: calc(60px + env(safe-area-inset-top)); }
  body.has-mini-broadcast .sidebar { padding-top: calc(60px + env(safe-area-inset-top)); }
}

/* ═══ SCREEN SHARE CONFIRMATION DIALOG ═══ */
#share-confirm-dialog {
  position: fixed; inset: 0; z-index: 99997;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s ease;
}
.scd-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(8px);
}
.scd-card {
  position: relative; z-index: 1;
  background: linear-gradient(180deg, #2a2a2a, #1e1e1e);
  border-radius: 20px;
  padding: 1.75rem 1.5rem;
  max-width: 360px;
  width: 90%;
  text-align: center;
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 20px 60px rgba(0,0,0,.7);
  animation: gcSlideIn .3s cubic-bezier(.34,1.4,.64,1);
  color: #fff;
}
.scd-icon { font-size: 3rem; margin-bottom: .75rem; }
.scd-title { font-size: 1.15rem; font-weight: 800; margin-bottom: .5rem; }
.scd-desc {
  font-size: .85rem;
  color: rgba(255,255,255,.7);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}
.scd-actions {
  display: flex; gap: .65rem;
}
.scd-btn {
  flex: 1;
  padding: .75rem;
  border-radius: var(--radius-full);
  font-weight: 700; font-size: .9rem;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: var(--transition);
}
.scd-cancel {
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.85);
}
.scd-cancel:hover { background: rgba(255,255,255,.15); }
.scd-confirm {
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: var(--on-primary);
}
.scd-confirm:hover { transform: scale(1.02); box-shadow: 0 6px 20px rgba(208,188,255,.4); }

/* ═══ TAP-TO-PLAY AUDIO OVERLAY (mobile autoplay fallback) ═══ */
#tap-to-play-overlay {
  position: fixed; inset: 0; z-index: 99998;
  background: rgba(0, 0, 0, .85);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  animation: fadeIn .25s ease;
}
.tap-play-card {
  background: linear-gradient(135deg, var(--surface-high), var(--surface-low));
  padding: 2.5rem 2rem;
  border-radius: var(--radius-xl);
  text-align: center;
  max-width: 320px;
  border: 1px solid rgba(255, 255, 255, .1);
  animation: tapPlayPulse 1.5s ease-in-out infinite;
}
@keyframes tapPlayPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(208, 188, 255, .4); }
  50% { box-shadow: 0 0 0 20px rgba(208, 188, 255, 0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.tap-play-icon { font-size: 4rem; margin-bottom: 1rem; }
.tap-play-title { font-size: 1.2rem; font-weight: 700; margin-bottom: .5rem; color: #fff; }
.tap-play-hint { font-size: .85rem; color: var(--on-surface-variant); }

/* ═══ RATE LIMIT BANNER ═══ */
#rate-limit-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 99999;
  background: linear-gradient(135deg, #ff3b30, #ff6b6b);
  color: #fff;
  padding: 1rem 1.25rem;
  box-shadow: 0 8px 30px rgba(255, 59, 48, .4);
  animation: fadeSlideUp .3s ease;
}
.rl-banner-inner {
  display: flex; align-items: flex-start; gap: 1rem;
  max-width: 700px; margin: 0 auto;
}
.rl-icon { font-size: 1.8rem; flex-shrink: 0; }
.rl-body { flex: 1; }
.rl-title { font-weight: 800; font-size: 1rem; margin-bottom: .35rem; }
.rl-msg { font-size: .85rem; line-height: 1.6; opacity: .95; }
.rl-btn {
  background: rgba(255,255,255,.2);
  color: #fff;
  padding: .5rem 1.25rem;
  border-radius: var(--radius-full);
  margin-top: .75rem;
  font-weight: 700;
  font-size: .85rem;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,.3);
}
.rl-btn:hover { background: rgba(255,255,255,.35); }
.rl-close {
  background: transparent; color: #fff;
  font-size: 1.5rem; line-height: 1;
  cursor: pointer; width: 32px; height: 32px;
  border-radius: 50%; flex-shrink: 0;
}
.rl-close:hover { background: rgba(255,255,255,.15); }

/* ═══════════════════════════════════════════════════════════════
   LIVE STREAMING - Midnight Pulse aesthetic
   ═══════════════════════════════════════════════════════════════ */

/* Live button in sidebar */
.icon-btn.live-btn { position: relative; }
.icon-btn.live-btn:hover { background: rgba(255, 59, 48, .15); color: #ff3b30; }

/* Pulsing red dot */
.live-dot-pulse {
  display: inline-block;
  width: 8px; height: 8px;
  background: #ff3b30;
  border-radius: 50%;
  margin-left: .35rem;
  vertical-align: middle;
  animation: livePulse 1.4s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(255, 59, 48, .7);
}
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 48, .7); transform: scale(1); }
  50% { box-shadow: 0 0 0 8px rgba(255, 59, 48, 0); transform: scale(1.1); }
}

/* Streams list modal */
.streams-modal { max-width: 520px; }
.start-stream-btn {
  background: linear-gradient(135deg, #ff3b30, #ff6b6b) !important;
  color: #fff !important;
  margin-bottom: 1.25rem;
}
.start-stream-btn:hover { box-shadow: 0 8px 30px rgba(255, 59, 48, .35) !important; }
.streams-list-divider {
  text-align: center;
  font-size: .8rem;
  color: var(--on-surface-variant);
  margin: 1rem 0 .75rem;
  letter-spacing: .03em;
}
.streams-list {
  display: flex; flex-direction: column; gap: .75rem;
  max-height: 50vh;
  overflow-y: auto;
  padding-left: .25rem;
}

/* Stream cards */
.stream-card {
  display: flex; gap: .85rem;
  background: var(--surface-high);
  border-radius: var(--radius-lg);
  padding: .75rem;
  cursor: pointer;
  transition: var(--transition);
}
.stream-card:hover {
  transform: translateY(-2px);
  background: var(--surface-bright);
  box-shadow: 0 8px 30px rgba(208, 188, 255, .08);
}
.stream-card-thumb {
  position: relative;
  width: 100px; height: 70px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-lowest);
  flex-shrink: 0;
}
.stream-card-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.stream-card-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  background: linear-gradient(135deg, var(--surface-lowest), var(--surface-high));
}
.stream-card-live {
  position: absolute;
  top: 6px; right: 6px;
  background: #ff3b30;
  color: #fff;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: .68rem;
  font-weight: 700;
  display: flex; align-items: center; gap: 4px;
}
.stream-card-live .live-dot-pulse {
  background: #fff;
  width: 6px; height: 6px;
  margin: 0;
}
.stream-card-viewers {
  position: absolute;
  bottom: 6px; left: 6px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: .7rem;
  backdrop-filter: blur(8px);
}
.stream-card-info {
  flex: 1;
  display: flex; flex-direction: column;
  justify-content: center;
  gap: .35rem;
  min-width: 0;
}
.stream-card-title {
  font-weight: 700;
  font-size: .92rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stream-card-broadcaster {
  display: flex; align-items: center; gap: .5rem;
  font-size: .8rem;
  color: var(--on-surface-variant);
}
.avatar.avatar-xs {
  width: 22px; height: 22px;
  font-size: .7rem;
}

/* Ringtone settings */
.ringtone-settings { padding-top: .5rem; border-top: 1px solid rgba(73, 68, 84, .15); margin-top: .25rem; }
.ringtone-row {
  display: flex; gap: .5rem; align-items: center;
}
.ringtone-row .auth-style-select { flex: 1; }
.ringtone-preview-btn {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--primary), var(--primary-container)) !important;
  color: var(--on-primary) !important;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.ringtone-preview-btn:hover { transform: scale(1.05); }
.ringtone-hint {
  display: block;
  margin-top: .5rem;
  font-size: .72rem;
  color: var(--on-surface-variant);
}

/* Auth-style select */
.auth-style-select {
  background: var(--surface-highest);
  color: var(--on-surface);
  border: none;
  outline: none;
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .95rem;
  width: 100%;
  cursor: pointer;
}

/* ─── Stream Overlay (broadcaster & viewer) ─── */
.stream-overlay {
  position: fixed;
  inset: 0;
  background: var(--surface-lowest);
  z-index: 9990;
  display: flex; flex-direction: column;
}
.stream-container {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "topbar topbar"
    "video chat"
    "controls controls";
  gap: 0;
  background: var(--surface);
}

.stream-top-bar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface-lowest);
}
.stream-live-badge {
  background: #ff3b30;
  color: #fff;
  padding: .35rem .85rem;
  border-radius: var(--radius-full);
  font-size: .75rem;
  font-weight: 700;
  display: flex; align-items: center; gap: .35rem;
}
.stream-live-badge .live-dot-pulse {
  background: #fff; margin: 0; width: 6px; height: 6px;
}
.stream-broadcaster-info {
  flex: 1;
  display: flex; flex-direction: column;
  min-width: 0;
}
.stream-broadcaster-info span { font-weight: 700; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stream-broadcaster-info small { color: var(--on-surface-variant); font-size: .75rem; }
.stream-stats {
  display: flex; gap: .75rem;
  font-size: .85rem;
  color: var(--on-surface-variant);
}
.stream-stats span { background: var(--surface-high); padding: .35rem .75rem; border-radius: var(--radius-full); }

/* Video area */
.stream-video-area {
  grid-area: video;
  position: relative;
  background: #000;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.stream-video, .stream-video-frame {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
}
.stream-video-frame {
  display: block;
}
.stream-loading {
  position: absolute;
  inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(14, 14, 14, .9);
  color: var(--on-surface-variant);
  gap: 1rem;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--surface-high);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Chat panel inside stream */
.stream-chat-panel {
  grid-area: chat;
  background: var(--surface-lowest);
  display: flex; flex-direction: column;
  border-right: 1px solid rgba(73, 68, 84, .15);
  min-height: 0;
}
.stream-chat-panel.hidden-chat { display: none; }
.stream-chat-header {
  padding: 1rem 1.25rem;
  font-weight: 700;
  font-size: .9rem;
  background: var(--surface-low);
}
.stream-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex; flex-direction: column;
  gap: .85rem;
  min-height: 0;
}
.stream-chat-msg {
  display: flex; gap: .5rem;
  animation: fadeSlideUp .25s ease;
}
.stream-chat-msg-body { flex: 1; min-width: 0; }
.stream-chat-msg-name {
  font-size: .72rem;
  color: var(--on-surface-variant);
  margin-bottom: .15rem;
  font-weight: 600;
}
.stream-chat-msg-text {
  font-size: .88rem;
  word-wrap: break-word;
  color: var(--on-surface);
}
.stream-chat-msg.mine .stream-chat-msg-name { color: var(--primary); }
.stream-chat-input-row {
  display: flex; gap: .5rem;
  padding: .75rem 1rem;
  background: var(--surface-low);
}
.stream-chat-input-row input {
  flex: 1;
  background: var(--surface-highest);
  font-size: .85rem;
  padding: .6rem .85rem;
}
.stream-chat-input-row .btn-send {
  width: 40px; height: 40px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: var(--on-primary);
  display: flex; align-items: center; justify-content: center;
}
.stream-chat-input-row .btn-send svg { width: 16px; height: 16px; }

/* Stream controls bar */
.stream-controls {
  grid-area: controls;
  display: flex; justify-content: center; align-items: center; gap: .9rem;
  padding: 1.25rem;
  background: var(--surface-lowest);
  position: relative; z-index: 5;
}
.stream-controls .call-btn {
  width: 56px; height: 56px;
  flex-shrink: 0;
}

/* End stream button — extra prominent */
.end-stream-btn {
  width: auto !important;
  min-width: 56px;
  padding: 0 1.25rem;
  background: linear-gradient(135deg, #ff3b30, #d62828) !important;
  border-radius: var(--radius-full) !important;
  color: #fff !important;
  display: flex !important; align-items: center !important; gap: .5rem;
  font-weight: 700; font-size: .9rem;
  box-shadow: 0 6px 25px rgba(255, 59, 48, .45);
  animation: endBtnPulse 2.5s ease-in-out infinite;
}
@keyframes endBtnPulse {
  0%, 100% { box-shadow: 0 6px 25px rgba(255, 59, 48, .45); }
  50% { box-shadow: 0 6px 35px rgba(255, 59, 48, .7); }
}
.end-stream-btn:hover {
  background: linear-gradient(135deg, #ff5544, #ee3322) !important;
  transform: scale(1.05);
}
.end-stream-btn svg { width: 22px; height: 22px; }
.end-stream-label { white-space: nowrap; }
@media (max-width: 480px) {
  .end-stream-label { display: none; }  /* tiny phones: icon only */
  .end-stream-btn { padding: 0; width: 56px !important; min-width: 56px; }
}

/* Mobile responsive — restructure as FLEX for reliable controls visibility */
@media (max-width: 768px) {
  .stream-overlay {
    height: 100vh;
    height: 100dvh; /* dynamic viewport — accounts for mobile address bar */
  }
  .stream-container {
    display: flex !important;
    flex-direction: column;
    height: 100%;
    grid-template-areas: none;
    grid-template-columns: unset;
    grid-template-rows: unset;
  }
  .stream-top-bar { flex-shrink: 0; padding: .65rem .85rem; }
  .stream-video-area { flex: 1 1 0; min-height: 0; }
  .stream-chat-panel {
    flex-shrink: 0;
    max-height: 40vh;
    border-right: none;
    border-top: 1px solid rgba(73, 68, 84, .15);
    display: none; /* HIDDEN by default on mobile — user opens via chat button */
  }
  .stream-chat-panel.show-on-mobile { display: flex; }
  .stream-controls {
    flex-shrink: 0;
    padding: .75rem .65rem max(1rem, env(safe-area-inset-bottom));
    gap: .55rem;
    background: var(--surface-lowest);
  }
  .stream-controls .call-btn { width: 46px; height: 46px; }
  .stream-broadcaster-info span { font-size: .85rem; }
  .stream-stats { font-size: .72rem; gap: .4rem; }
  .stream-stats span { padding: .2rem .55rem; }
  .stream-card-thumb { width: 80px; height: 56px; }
  .stream-card-title { font-size: .85rem; }
  .streams-modal { max-width: 95vw; }
  /* Hide hidden-chat behavior on mobile — we use show-on-mobile instead */
  .stream-chat-panel.hidden-chat { display: none; }
}
