:root,
[data-theme="light"] {
  --tg-blue: #3390ec;
  --tg-blue-hover: #2882dc;
  --tg-blue-active: #1f73c7;
  --tg-blue-soft: rgba(51, 144, 236, 0.12);
  --tg-green-online: #4ecc5e;
  --tg-check-read: #0099ff;
  --tg-check-sent: #5fae4e;
  --tg-danger: #e53935;
  --tg-warn: #f59e0b;

  --bg-surface: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-secondary: #f4f4f5;
  --bg-hover: #f1f3f5;
  --bg-active-chat: #3390ec;

  --text-primary: #0f172a;
  --text-secondary: #707579;
  --text-muted: #9aa0a6;
  --text-on-accent: #ffffff;

  --border-subtle: #e6e8eb;
  --bubble-out-bg: #eeffde;
  --bubble-out-text: #0f172a;
  --bubble-out-meta: #4fae4e;
  --bubble-in-bg: #ffffff;
  --bubble-in-text: #0f172a;
  --bubble-in-meta: #8a929a;
  --bubble-shadow: 0 1px 2px rgba(16, 35, 47, 0.13);

  --chat-wallpaper-grad: linear-gradient(135deg, #d6e5c8 0%, #a5cca6 36%, #8ec0b6 72%, #c4dec0 100%);
  --service-pill-bg: rgba(65, 108, 69, 0.48);
  --service-pill-text: #ffffff;
  --modal-backdrop: rgba(15, 23, 42, 0.52);
  --shadow-elevated: 0 12px 34px rgba(15, 23, 42, 0.16);
}

[data-theme="dark"] {
  --tg-blue: #5288c1;
  --tg-blue-hover: #6499d1;
  --tg-blue-active: #4477ad;
  --tg-blue-soft: rgba(82, 136, 193, 0.18);
  --tg-green-online: #4ecc5e;
  --tg-check-read: #4fc3f7;
  --tg-check-sent: #78a9dd;
  --tg-danger: #ef5350;
  --tg-warn: #ffb74d;

  --bg-surface: #17212b;
  --bg-sidebar: #17212b;
  --bg-secondary: #242f3d;
  --bg-hover: #202b36;
  --bg-active-chat: #2b5278;

  --text-primary: #f5f5f5;
  --text-secondary: #8a9aa9;
  --text-muted: #6c7883;
  --text-on-accent: #ffffff;

  --border-subtle: #101921;
  --bubble-out-bg: #2b5278;
  --bubble-out-text: #f5f5f5;
  --bubble-out-meta: #7eb8f7;
  --bubble-in-bg: #182533;
  --bubble-in-text: #f5f5f5;
  --bubble-in-meta: #6c7883;
  --bubble-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);

  --chat-wallpaper-grad: linear-gradient(135deg, #0e1621 0%, #131f2e 50%, #0d1520 100%);
  --service-pill-bg: rgba(24, 37, 51, 0.78);
  --service-pill-text: #d8e4f0;
  --modal-backdrop: rgba(0, 0, 0, 0.68);
  --shadow-elevated: 0 14px 40px rgba(0, 0, 0, 0.48);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body, #app {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.45;
}

/* Telegram Avatar Gradients */
.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #ffffff;
  font-weight: 600;
  user-select: none;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.avatar-sm { width: 36px; height: 36px; font-size: 14px; }
.avatar-md { width: 42px; height: 42px; font-size: 16px; }
.avatar-lg { width: 50px; height: 50px; font-size: 18px; }
.avatar-xl { width: 68px; height: 68px; font-size: 24px; }

.avatar-c0 { background: linear-gradient(135deg, #52b6f7, #228be6); }
.avatar-c1 { background: linear-gradient(135deg, #69db7c, #2f9e44); }
.avatar-c2 { background: linear-gradient(135deg, #ffa94d, #e8590c); }
.avatar-c3 { background: linear-gradient(135deg, #b197fc, #7048e8); }
.avatar-c4 { background: linear-gradient(135deg, #ff8787, #e03131); }
.avatar-c5 { background: linear-gradient(135deg, #3bc9db, #0c8599); }
.avatar-c6 { background: linear-gradient(135deg, #f783ac, #c2255c); }

.online-dot {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--tg-green-online);
  border: 2px solid var(--bg-sidebar);
}
.chat-item.active .online-dot {
  border-color: var(--bg-active-chat);
}

/*Peer name colors in groups*/
.peer-c0 { color: #1d80d6; }
.peer-c1 { color: #2b9348; }
.peer-c2 { color: #e06d06; }
.peer-c3 { color: #7950f2; }
.peer-c4 { color: #e03131; }
.peer-c5 { color: #0ca678; }
.peer-c6 { color: #d6336c; }
[data-theme="dark"] .peer-c0 { color: #64b5f6; }
[data-theme="dark"] .peer-c1 { color: #81c784; }
[data-theme="dark"] .peer-c2 { color: #ffb74d; }
[data-theme="dark"] .peer-c3 { color: #b39ddb; }
[data-theme="dark"] .peer-c4 { color: #e57373; }
[data-theme="dark"] .peer-c5 { color: #4dd0e1; }
[data-theme="dark"] .peer-c6 { color: #f48fb1; }

/* ============== LOGIN PAGE (Telegram Web Style) ============== */
.login-screen {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--chat-wallpaper-grad);
  padding: 20px;
  overflow-y: auto;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border-radius: 20px;
  box-shadow: var(--shadow-elevated);
  padding: 36px 32px 28px;
  text-align: center;
  position: relative;
  z-index: 2;
  animation: fadeUp 0.25s ease-out;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.tg-logo-circle {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  margin: 0 auto 18px;
  background: linear-gradient(145deg, #3BB4F8 0%, #1E88E5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 22px rgba(51, 144, 236, 0.35);
}

.tg-logo-circle svg {
  width: 46px;
  height: 46px;
  fill: #ffffff;
  transform: translateX(-2px);
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 22px;
}

.role-tabs {
  display: flex;
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 22px;
}

.role-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.role-tab.active {
  background: var(--bg-surface);
  color: var(--tg-blue);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.form-group {
  text-align: left;
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.tg-input {
  width: 100%;
  padding: 12px 15px;
  border-radius: 12px;
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color 0.16s, box-shadow 0.16s;
}

.tg-input:focus {
  border-color: var(--tg-blue);
  box-shadow: 0 0 0 3px var(--tg-blue-soft);
}

.tg-btn-primary {
  width: 100%;
  padding: 13px 18px;
  border: none;
  border-radius: 12px;
  background: var(--tg-blue);
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tg-btn-primary:hover {
  background: var(--tg-blue-hover);
}
.tg-btn-primary:active {
  transform: scale(0.99);
}
.tg-btn-primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.login-error {
  background: rgba(229, 57, 53, 0.1);
  color: var(--tg-danger);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  text-align: left;
}

.login-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.apk-download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--tg-blue);
  text-decoration: none;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--tg-blue-soft);
  transition: background 0.15s;
}
.apk-download-link:hover {
  background: rgba(51, 144, 236, 0.2);
}

/* ============== MAIN TELEGRAM SHELL ============== */
.tg-shell {
  width: 100%;
  height: 100%;
  display: flex;
  background: var(--bg-surface);
  position: relative;
}

/* Left Sidebar */
.tg-sidebar {
  width: 360px;
  min-width: 310px;
  max-width: 400px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  z-index: 10;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 10px 12px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.icon-btn.accent {
  color: var(--tg-blue);
  background: var(--tg-blue-soft);
}

.search-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 30px 0 36px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: all 0.16s;
}
.search-input:focus {
  background: var(--bg-surface);
  border-color: var(--tg-blue);
}

/* Profile & Quick Bar under Search */
.sidebar-user-strip {
  padding: 6px 14px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.me-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.me-info {
  min-width: 0;
}
.me-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 5px;
}
.me-sub {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.ws-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tg-green-online);
  display: inline-block;
}
.ws-dot.offline {
  background: var(--tg-warn);
}

.role-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--tg-blue-soft);
  color: var(--tg-blue);
}

.admin-open-btn {
  border: none;
  background: var(--tg-blue);
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: background 0.15s;
}
.admin-open-btn:hover {
  background: var(--tg-blue-hover);
}

.logout-text-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color 0.15s;
}
.logout-text-link:hover {
  color: var(--tg-danger);
  text-decoration: underline;
}

/* Folder Tabs */
.folder-tabs {
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 4px;
  overflow-x: auto;
}

.folder-tab {
  position: relative;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 12px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s;
}
.folder-tab:hover {
  color: var(--text-primary);
}
.folder-tab.active {
  color: var(--tg-blue);
}
.folder-tab.active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--tg-blue);
}

.tab-pill {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}
.folder-tab.active .tab-pill {
  background: var(--tg-blue);
  color: #ffffff;
}

/* Conversation List */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.12s;
  user-select: none;
  margin-bottom: 2px;
}

.chat-item:hover {
  background: var(--bg-hover);
}

.chat-item.active {
  background: var(--bg-active-chat);
  color: #ffffff;
}

.chat-item-body {
  flex: 1;
  min-width: 0;
}

.chat-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.chat-item-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-item-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.chat-item.active .chat-item-meta {
  color: rgba(255, 255, 255, 0.85);
}

.chat-item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-item-preview {
  font-size: 13.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.chat-item.active .chat-item-preview {
  color: rgba(255, 255, 255, 0.88);
}

.chat-item-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.mention-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--tg-blue);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-item.active .mention-badge {
  background: #ffffff;
  color: var(--bg-active-chat);
}

.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--tg-green-online);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-item.active .unread-badge {
  background: #ffffff;
  color: var(--bg-active-chat);
}

/* ============== MAIN CHAT VIEWPORT ============== */
.tg-main {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  background: var(--chat-wallpaper-grad);
}

/* Subtle Telegram SVG Pattern Overlay */
.tg-main::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg width='120' height='120' viewBox='0 0 120 120' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%231b3a24' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 28l18-7-7 18-3-7-8-4z'/%3E%3Ccircle cx='85' cy='30' r='9'/%3E%3Cpath d='M81 30h8M85 26v8'/%3E%3Crect x='20' y='76' width='22' height='16' rx='3'/%3E%3Cpath d='M25 82h12M25 87h8'/%3E%3Cpath d='M78 80l16-6-5 17-4-6-7-5z'/%3E%3Ccircle cx='56' cy='56' r='4'/%3E%3C/g%3E%3C/svg%3E");
  z-index: 0;
}

.chat-header {
  height: 58px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 5;
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  cursor: pointer;
}

.mobile-back-btn {
  display: none;
}

.chat-header-info {
  min-width: 0;
}
.chat-header-title {
  font-size: 15.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-sub.online {
  color: var(--tg-blue);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill-action-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
}
.pill-action-btn:hover {
  border-color: var(--tg-blue);
  color: var(--tg-blue);
}

/* Message Stream */
.messages-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 2;
}

.messages-inner {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.date-divider,
.system-message-row {
  display: flex;
  justify-content: center;
  margin: 6px 0;
}

.service-pill {
  background: var(--service-pill-bg);
  color: var(--service-pill-text);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 12.5px;
  font-weight: 500;
  padding: 4px 13px;
  border-radius: 999px;
  text-align: center;
  max-width: 88%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Message Row & Bubble */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 2px 0;
  position: relative;
}

.msg-row.outgoing {
  justify-content: flex-end;
}

.msg-row.incoming {
  justify-content: flex-start;
}

.msg-bubble {
  position: relative;
  max-width: min(72%, 520px);
  min-width: 56px;
  padding: 7px 11px 6px;
  border-radius: 15px;
  box-shadow: var(--bubble-shadow);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  transition: transform 0.12s, box-shadow 0.12s;
}

.msg-bubble.inline-short {
  display: inline-flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 10px 6px 12px;
}

.msg-bubble.inline-short .msg-footer {
  margin-top: 0;
  margin-bottom: -1px;
  flex-shrink: 0;
}

.msg-bubble.pure-image {
  padding: 4px;
  min-width: 0;
}

.msg-bubble.pure-image .msg-image-wrap {
  margin: 0;
  border-radius: 12px;
}

.msg-bubble.pure-image .msg-footer-overlay {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(0, 0, 0, 0.56);
  color: #ffffff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}
.msg-bubble.pure-image .msg-footer-overlay .receipt-badge.read {
  color: #64d2ff;
}
.msg-bubble.pure-image .msg-footer-overlay .receipt-badge.sent,
.msg-bubble.pure-image .msg-footer-overlay .receipt-badge.delivered {
  color: #ffffff;
}

.msg-row.incoming .msg-bubble {
  background: var(--bubble-in-bg);
  color: var(--bubble-in-text);
  border-bottom-left-radius: 4px;
}

.msg-row.outgoing .msg-bubble {
  background: var(--bubble-out-bg);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 4px;
}

.msg-bubble.mentioned-me {
  box-shadow: 0 0 0 2px var(--tg-blue), var(--bubble-shadow);
}

.msg-sender-line {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.teacher-tag {
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--tg-blue);
  color: #ffffff;
}

/* Reply Quote inside Bubble */
.msg-reply-quote {
  border-left: 3px solid var(--tg-blue);
  background: rgba(51, 144, 236, 0.09);
  border-radius: 4px 8px 8px 4px;
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 12.5px;
  cursor: pointer;
}
.msg-reply-quote-sender {
  font-weight: 700;
  color: var(--tg-blue);
}
.msg-reply-quote-text {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-text {
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.mention-token {
  display: inline-block;
  color: var(--tg-blue);
  font-weight: 600;
  background: var(--tg-blue-soft);
  padding: 0 5px;
  border-radius: 5px;
}
.mention-token.me {
  background: var(--tg-blue);
  color: #ffffff;
}

/* Image Message */
.msg-image-wrap {
  margin: 2px -4px 4px;
  border-radius: 11px;
  overflow: hidden;
  position: relative;
  cursor: zoom-in;
  background: rgba(0, 0, 0, 0.04);
  max-width: 320px;
}

.msg-image {
  display: block;
  width: 100%;
  max-width: 320px;
  max-height: 280px;
  object-fit: cover;
  border-radius: 11px;
  transition: transform 0.2s ease;
}
.msg-image-wrap:hover .msg-image {
  transform: scale(1.015);
}

.img-zoom-hint {
  position: absolute;
  right: 8px;
  top: 8px;
  background: rgba(0, 0, 0, 0.52);
  color: #ffffff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  pointer-events: none;
}

/* File Attachment Card inside Bubble */
.msg-file-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 4px;
  text-decoration: none;
  color: inherit;
  min-width: 210px;
}

.msg-file-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--tg-blue);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.msg-file-info {
  flex: 1;
  min-width: 0;
}
.msg-file-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-file-size {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Bubble Meta Footer (Time + WhatsApp Checkmarks) */
.msg-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 3px;
  font-size: 11.5px;
  user-select: none;
}

.msg-row.incoming .msg-footer {
  color: var(--bubble-in-meta);
}
.msg-row.outgoing .msg-footer {
  color: var(--bubble-out-meta);
}

.receipt-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 600;
}
.receipt-badge svg {
  width: 16px;
  height: 15px;
}
.receipt-badge.sent {
  color: #7c8b80;
}
.receipt-badge.delivered {
  color: #5b7263;
}
.receipt-badge.read {
  color: var(--tg-check-read);
}
.receipt-badge.clickable-receipt {
  cursor: pointer;
  padding: 1px 5px;
  border-radius: 6px;
  transition: background 0.14s;
}
.receipt-badge.clickable-receipt:hover {
  background: rgba(0, 153, 255, 0.12);
}

.group-readers-bar {
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px dashed rgba(112, 117, 121, 0.18);
  font-size: 11.5px;
  color: var(--tg-check-read);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}
.group-readers-bar:hover {
  text-decoration: underline;
}

/* Bubble Hover Actions (Reply & Recall) */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.14s;
}
.msg-row:hover .msg-actions {
  opacity: 1;
}

.msg-act-btn {
  border: none;
  background: rgba(255, 255, 255, 0.9);
  color: #334155;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}
[data-theme="dark"] .msg-act-btn {
  background: #242f3d;
  color: #e2e8f0;
}
.msg-act-btn:hover {
  color: var(--tg-blue);
}
.msg-act-btn.danger:hover {
  color: var(--tg-danger);
}

/* ============== COMPOSER & POPOVERS ============== */
.composer-zone {
  position: relative;
  z-index: 6;
  padding: 8px 16px 14px;
}

.composer-inner {
  max-width: 820px;
  margin: 0 auto;
  position: relative;
}

/* Reply Banner above Composer */
.composer-reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  border-radius: 14px 14px 0 0;
  padding: 7px 14px;
  font-size: 13px;
}

/* @Mention Autocomplete Popover */
.mention-popover {
  position: absolute;
  left: 0;
  right: 56px;
  bottom: calc(100% + 8px);
  background: var(--bg-surface);
  border-radius: 14px;
  box-shadow: var(--shadow-elevated);
  border: 1px solid var(--border-subtle);
  max-height: 250px;
  overflow-y: auto;
  z-index: 25;
  padding: 6px;
}

.mention-popover-header {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 4px 10px 6px;
  display: flex;
  justify-content: space-between;
}

.mention-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s;
}
.mention-option:hover,
.mention-option.active {
  background: var(--tg-blue-soft);
}

/* Emoji Picker Popover */
.emoji-popover {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  width: 330px;
  max-width: 92vw;
  background: var(--bg-surface);
  border-radius: 16px;
  box-shadow: var(--shadow-elevated);
  border: 1px solid var(--border-subtle);
  z-index: 26;
  padding: 10px;
}

.emoji-cats {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 6px;
}
.emoji-cat-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 5px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}
.emoji-cat-btn.active {
  background: var(--tg-blue-soft);
  color: var(--tg-blue);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}
.emoji-cell {
  border: none;
  background: transparent;
  font-size: 21px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.emoji-cell:hover {
  background: var(--bg-hover);
  transform: scale(1.12);
}

/* Composer Bar */
.composer-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer-box {
  flex: 1;
  background: var(--bg-surface);
  border-radius: 22px;
  box-shadow: var(--bubble-shadow);
  display: flex;
  align-items: center;
  padding: 4px 8px;
  gap: 4px;
}

.composer-textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.4;
  padding: 8px 6px;
  max-height: 120px;
  resize: none;
  outline: none;
  font-family: inherit;
}

.send-fab {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--tg-blue);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(51, 144, 236, 0.35);
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.send-fab:hover {
  background: var(--tg-blue-hover);
}
.send-fab:active {
  transform: scale(0.95);
}
.send-fab svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* Empty Chat Placeholder */
.empty-chat-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  padding: 24px;
}

/* ============== MODALS & DRAWERS ============== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-backdrop);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  background: var(--bg-surface);
  border-radius: 18px;
  box-shadow: var(--shadow-elevated);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeUp 0.18s ease-out;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
}

.modal-tabs {
  display: flex;
  background: var(--bg-secondary);
  padding: 6px 16px 0;
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
}
.modal-tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.modal-tab.active {
  color: var(--tg-blue);
  border-bottom-color: var(--tg-blue);
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
}

.admin-section {
  background: var(--bg-secondary);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.admin-section-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.inline-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.student-list-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.student-row-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-surface);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
}

.btn-sm {
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-sm:hover {
  border-color: var(--tg-blue);
  color: var(--tg-blue);
}
.btn-sm.primary {
  background: var(--tg-blue);
  border-color: var(--tg-blue);
  color: #ffffff;
}
.btn-sm.danger {
  color: var(--tg-danger);
}
.btn-sm.danger:hover {
  border-color: var(--tg-danger);
  background: rgba(229, 57, 53, 0.08);
}

/* Fullscreen Original Image Lightbox */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.92);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox-toolbar {
  position: absolute;
  top: 16px;
  right: 20px;
  display: flex;
  gap: 10px;
  z-index: 205;
}

.lightbox-btn {
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.lightbox-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.lightbox-img {
  max-width: 94vw;
  max-height: 86vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  transition: transform 0.2s ease;
}

/* Floating In-App Push Toast */
.push-toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 180;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 350px;
  width: calc(100vw - 32px);
  pointer-events: none;
}

.push-toast {
  pointer-events: auto;
  background: var(--bg-surface);
  color: var(--text-primary);
  border-left: 4px solid var(--tg-blue);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow-elevated);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  animation: fadeUp 0.2s ease-out;
}

/* Responsive Mobile Layout */
@media (max-width: 780px) {
  .tg-sidebar {
    width: 100%;
    max-width: 100%;
  }
  .tg-shell.mobile-chat-open .tg-sidebar {
    display: none;
  }
  .tg-shell:not(.mobile-chat-open) .tg-main {
    display: none;
  }
  .mobile-back-btn {
    display: inline-flex;
  }
  .msg-bubble {
    max-width: 85%;
  }
  .msg-actions {
    opacity: 1;
  }
}
