/* Telegram Web K — light theme clone */
:root {
  --tg-sidebar-w: 420px;
  --tg-header-h: 56px;
  --tg-peer-bg: #99ba92;
  --tg-peer-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'%3E%3Cg fill='%23ffffff' fill-opacity='0.08'%3E%3Ccircle cx='30' cy='40' r='8'/%3E%3Crect x='80' y='20' width='14' height='14' rx='3' transform='rotate(15 87 27)'/%3E%3Cpath d='M150 50l10 6-10 6-6-10z'/%3E%3Ccircle cx='40' cy='120' r='6'/%3E%3Crect x='120' y='100' width='12' height='12' rx='2'/%3E%3Cpath d='M170 140c0 8-6 14-14 14s-14-6-14-14 6-14 14-14 14 6 14 14z'/%3E%3Ccircle cx='90' cy='170' r='7'/%3E%3Crect x='20' y='160' width='10' height='10' rx='2' transform='rotate(-20 25 165)'/%3E%3C/g%3E%3C/svg%3E");
  --tg-active: rgba(51, 144, 236, 0.08);
  --tg-hover: #f4f4f5;
  --tg-text: #000;
  --tg-text-secondary: #707579;
  --tg-border: #dadce0;
  --tg-input-bg: #f4f4f5;
}

.tg-app {
  display: flex;
  height: 100%;
  background: #fff;
  position: relative;
  overflow: hidden;
}

/* ── Sidebar ── */
.tg-sidebar {
  width: 100%;
  max-width: var(--tg-sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--tg-border);
  background: #fff;
  z-index: 2;
}

.tg-sidebar-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(6px + var(--safe-top)) 8px 8px;
  background: #fff;
}

.sidebar-account {
  flex: 0 0 auto;
  padding: 0 14px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  background: #fff;
  border-bottom: 1px solid var(--tg-border);
}

.tg-search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--tg-input-bg);
  border-radius: 22px;
  padding: 0 12px;
  min-height: 42px;
}

.tg-search-wrap svg {
  flex-shrink: 0;
  color: var(--tg-text-secondary);
  opacity: 0.65;
}

.tg-search {
  flex: 1;
  border: 0;
  background: transparent;
  font-size: 15px;
  outline: none;
  color: var(--tg-text);
  min-width: 0;
}

.tg-search::placeholder { color: var(--tg-text-secondary); }

.tg-icon-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--tg-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.tg-icon-btn:hover { background: var(--tg-hover); }
.tg-icon-btn:active { background: #ebebeb; }
.tg-icon-btn svg { display: block; }

.tg-sidebar .chat-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tg-sidebar .chat-item {
  display: flex;
  gap: 12px;
  padding: 8px 10px 8px 12px;
  min-height: 72px;
  align-items: center;
  cursor: pointer;
  border-bottom: none;
  transition: background 0.1s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.tg-sidebar .chat-item:hover { background: var(--tg-hover); }
.tg-sidebar .chat-item.active { background: var(--tg-active); }

.tg-sidebar .avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.5px;
}

.tg-sidebar .chat-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--tg-text);
}

.tg-sidebar .chat-preview {
  font-size: 15px;
  color: var(--tg-text-secondary);
  margin-top: 3px;
}

.tg-sidebar .chat-time {
  font-size: 12px;
  color: var(--tg-text-secondary);
}

.tg-sidebar .badge {
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

/* ── Main / empty ── */
.tg-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--tg-peer-bg);
  background-image: var(--tg-peer-pattern);
  position: relative;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px 24px;
  text-align: center;
  background: #fff;
  background-image: none;
}

.chat-empty .empty-logo {
  width: 160px;
  height: 160px;
  opacity: 0.35;
  object-fit: contain;
  background: transparent !important;
}

.chat-empty h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 400;
  color: var(--tg-text);
  letter-spacing: -0.3px;
}

.chat-empty p {
  margin: 0;
  font-size: 14px;
  color: var(--tg-text-secondary);
  max-width: 280px;
  line-height: 1.45;
}

.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-pane.hidden { display: none !important; }

#chat-pane:not(.hidden),
.tg-main.chat-active #chat-pane:not(.hidden),
.tg-app.chat-open #chat-pane:not(.hidden) {
  display: flex !important;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

#chat-empty.hidden,
.chat-empty.hidden,
.tg-app.chat-open #chat-empty,
.tg-main.chat-active #chat-empty {
  display: none !important;
}

/* ── Chat header (white, like TG Web) ── */
.tg-chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--tg-header-h);
  padding: calc(4px + var(--safe-top)) 8px 4px 4px;
  background: #fff;
  border-bottom: 1px solid var(--tg-border);
  color: var(--tg-text);
  z-index: 3;
}

.tg-chat-header .tg-icon-btn { color: var(--tg-text-secondary); }

.tg-chat-header-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}

.tg-chat-header-main:hover { background: var(--tg-hover); }

.tg-chat-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 500;
  flex-shrink: 0;
}

.tg-chat-header-text { min-width: 0; }

.tg-chat-header-name {
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--tg-text);
}

.tg-chat-header-status {
  font-size: 13px;
  color: var(--tg-text-secondary);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tg-chat-header-status.online { color: var(--blue); }

.tg-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

/* ── Messages ── */
.tg-main .messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 12px;
  background: transparent;
  -webkit-overflow-scrolling: touch;
}

.typing-bar {
  flex: 0 0 auto;
  padding: 2px 16px 6px;
  font-size: 13px;
  color: var(--blue);
  background: rgba(255,255,255,.75);
  backdrop-filter: blur(4px);
}

.typing-bar.hidden { display: none !important; }

.date-sep {
  display: flex;
  justify-content: center;
  margin: 10px 0 6px;
  pointer-events: none;
}

.date-sep span {
  background: rgba(255,255,255,.88);
  color: var(--tg-text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 11px;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

/* Bubbles — TG shape: входящие слева (белые), исходящие справа (зелёные) */
.bubble-row {
  display: flex;
  width: 100%;
  margin-bottom: 3px;
  padding: 0 10px;
  box-sizing: border-box;
}
.bubble-row.in { justify-content: flex-start; }
.bubble-row.out { justify-content: flex-end; }
.bubble-row.in + .bubble-row.in .bubble { border-top-left-radius: 12px; }
.bubble-row.in .bubble:not(:first-child) { border-top-left-radius: 12px; }

.bubble {
  max-width: min(82vw, 320px);
  padding: 7px 11px 6px;
  border-radius: 16px;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
  word-wrap: break-word;
  position: relative;
}

.bubble.has-media { padding: 3px; max-width: min(82vw, 280px); }
.bubble.in {
  background: #ffffff !important;
  border-bottom-left-radius: 4px;
  margin-right: 48px;
  border: 1px solid rgba(0,0,0,.06);
}
.bubble.out {
  background: #d9f7a7 !important;
  border-bottom-right-radius: 4px;
  margin-left: 48px;
  border: 1px solid rgba(76,140,46,.25);
}
.bubble-row.out + .bubble-row.out .bubble { border-top-right-radius: 12px; }

.bubble .sender {
  font-size: 13px;
  font-weight: 500;
  color: var(--blue);
  margin: 2px 4px 1px;
}

.bubble .text {
  font-size: 15px;
  line-height: 1.3125;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  padding: 0 2px;
  margin: 0;
  color: var(--tg-text);
}
.bubble .text strong { font-weight: 700; }
.bubble .text em { font-style: italic; }
.bubble .text s { text-decoration: line-through; }
.bubble .text a.msg-phone {
  color: #3390ec;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 500;
  white-space: nowrap;
}
.bubble.out .text a.msg-phone { color: #1b6fbf; }
.bubble .text a.msg-phone:active { opacity: 0.75; }
.bubble .text a.msg-link {
  color: #2481cc;
  text-decoration: underline;
  word-break: break-all;
}
.bubble.out .text a.msg-link { color: #1b6fbf; }
.bubble .text a.msg-link:active { opacity: 0.75; }
.link-preview {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.04);
  border-left: 3px solid #3390ec;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
}
.bubble.out .link-preview { background: rgba(0, 0, 0, 0.06); }
.link-preview-img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.link-preview-body { min-width: 0; flex: 1; }
.link-preview-site {
  font-size: 11px;
  color: #3390ec;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-preview-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-preview-desc {
  font-size: 12px;
  color: #707579;
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bubble .text .msg-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 4px;
}
.bubble .text .msg-pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: rgba(0, 0, 0, 0.06);
  padding: 6px 8px;
  border-radius: 8px;
  margin: 4px 0;
  white-space: pre-wrap;
  overflow-x: auto;
}
.bubble.out .text .msg-code,
.bubble.out .text .msg-pre { background: rgba(0, 0, 0, 0.08); }

.bubble.deleted .text { font-style: italic; color: var(--tg-text-secondary); }

.bubble .time-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 2px;
  padding: 0 2px;
  float: right;
  margin-left: 8px;
  position: relative;
  top: 4px;
}

.bubble .time-row .time {
  font-size: 11px;
  color: var(--tg-text-secondary);
  margin: 0;
}

.bubble .time.media-time {
  position: absolute;
  right: 6px;
  bottom: 5px;
  margin: 0;
  padding: 2px 6px 2px 8px;
  border-radius: 12px;
  background: rgba(0,0,0,.45);
  color: #fff;
  font-size: 11px;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 3px;
}

.bubble-media {
  display: block;
  overflow: hidden;
  border-radius: 10px;
  line-height: 0;
  max-width: min(82vw, 280px);
  background: #e8ecf0;
}
.bubble-media img,
.bubble-media video {
  display: block;
  width: auto;
  height: auto;
  max-width: min(82vw, 280px);
  max-height: 320px;
  object-fit: contain;
  cursor: pointer;
}
.bubble-media .msg-photo.loading-img {
  filter: blur(6px);
  opacity: .85;
  transition: filter .15s ease, opacity .15s ease;
}
.bubble-media video { cursor: default; background: #000; }

.tg-chat-header-main { cursor: pointer; }
.tg-chat-header-main:active { opacity: .85; }

.read-check { font-size: 15px; line-height: 1; color: var(--tg-text-secondary); opacity: 0.7; }
.read-check.read { color: #4fae4e; opacity: 1; }
.msg-status { display: inline-flex; align-items: center; margin-left: 3px; line-height: 1; vertical-align: middle; }
.msg-status .ck { font-size: 14px; font-style: normal; color: #8d969c; }
.msg-status .ck2 { margin-left: -7px; }
.msg-status.read .ck { color: #4fae4e; }
.msg-status.sending { color: var(--blue); font-size: 13px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tg-chat-header-status.online { color: var(--blue); }
.typing-bar { color: var(--blue); font-weight: 500; }

/* ── Composer (TG Web style) ── */
.tg-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: #fff;
  border-top: 1px solid var(--tg-border);
  position: relative;
}

.tg-composer-field {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  background: var(--tg-input-bg);
  border-radius: 22px;
  padding: 4px 4px 4px 2px;
  min-height: 44px;
}

.tg-composer-field textarea {
  flex: 1;
  resize: none;
  border: 0;
  background: transparent;
  padding: 10px 4px;
  font-size: 15px;
  font-family: inherit;
  max-height: 120px;
  min-height: 36px;
  outline: none;
  line-height: 1.3125;
}

.tg-composer-field .tg-icon-btn {
  width: 36px;
  height: 36px;
  margin-bottom: 2px;
  color: var(--tg-text-secondary);
}

.tg-composer-action {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.15s, transform 0.1s;
}

.tg-composer-action:hover { background: var(--blue-dark); }
.tg-composer-action:active { transform: scale(0.95); }
.tg-composer-action.mic-mode { background: transparent; color: var(--tg-text-secondary); }
.tg-composer-action.mic-mode:hover { background: var(--tg-hover); }
.tg-composer-action.recording { background: #e53935 !important; color: #fff !important; animation: socium-pulse 1s ease-in-out infinite; }
@keyframes socium-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.75; } }
.bubble-audio audio { width: min(240px, 100%); height: 36px; display: block; }

/* Voice messages — Telegram style */
.bubble.has-voice {
  padding: 4px 6px 18px;
  min-width: 210px;
  max-width: min(82vw, 280px);
  position: relative;
}
.bubble-voice { position: relative; }
.voice-player .voice-audio {
  display: none;
  width: 0;
  height: 0;
  position: absolute;
  pointer-events: none;
}
.voice-player {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 22px;
  padding: 5px 12px 5px 5px;
  min-width: 200px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.04);
}
.bubble.in .voice-player { background: #eef3f7; }
.voice-play {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: #3390ec;
  color: #fff;
  transition: transform 0.1s;
}
.voice-play:active { transform: scale(0.94); }
.bubble.out .voice-play { background: #4fae4e; }
.voice-play svg { display: block; }
.voice-play.playing .icon-play { display: none; }
.voice-play:not(.playing) .icon-pause { display: none; }
.voice-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: 2px;
}
.voice-wave {
  display: flex;
  align-items: flex-end;
  gap: 1.5px;
  height: 22px;
}
.voice-bar {
  flex: 1;
  min-width: 2px;
  max-width: 3px;
  border-radius: 2px;
  background: rgba(79, 174, 78, 0.35);
  transition: background 0.08s linear;
}
.bubble.in .voice-bar { background: rgba(51, 144, 236, 0.28); }
.voice-bar.played { background: #4fae4e; }
.bubble.in .voice-bar.played { background: #3390ec; }
.voice-dur {
  font-size: 11px;
  color: var(--tg-text-secondary);
  line-height: 1;
}
.bubble .time.voice-time {
  position: absolute;
  right: 8px;
  bottom: 3px;
  margin: 0;
  font-size: 11px;
  color: var(--tg-text-secondary);
  display: flex;
  align-items: center;
  gap: 3px;
  pointer-events: none;
}
.bubble.out .time.voice-time .msg-status .ck { color: #4fae4e; }

/* In-app update banner */
.app-update-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 10px 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, #e8f4fd, #d9f7a7);
  border: 1px solid rgba(51, 144, 236, 0.25);
  font-size: 13px;
  line-height: 1.3;
}
.app-update-banner.hidden { display: none !important; }
.app-update-banner strong { color: var(--blue); }
.app-update-btn {
  flex-shrink: 0;
  border: 0;
  border-radius: 18px;
  padding: 7px 14px;
  background: var(--blue);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.app-update-btn:disabled { opacity: 0.65; cursor: default; }
.settings-update-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--tg-border);
}
.settings-update-row .app-update-btn { padding: 8px 16px; }
.tg-composer-action:disabled { opacity: 0.4; cursor: default; }

/* Attach popup */
.attach-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 12px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 16px rgba(0,0,0,.16);
  padding: 8px;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  min-width: 240px;
}

.attach-menu.hidden { display: none !important; }

.attach-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  padding: 12px 8px;
  font-size: 12px;
  color: var(--tg-text-secondary);
  cursor: pointer;
  border-radius: 10px;
}

.attach-item:hover { background: var(--tg-hover); }

.attach-item .attach-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.attach-item[data-kind="photo"] .attach-icon { background: #e3f2fd; }
.attach-item[data-kind="video"] .attach-icon { background: #fce4ec; }
.attach-item[data-kind="file"] .attach-icon { background: #f3e5f5; }

.emoji-panel {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(100% + 6px);
  z-index: 12;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.16);
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: 320px;
  overflow: hidden;
}
.emoji-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #e8ecf0;
  flex-shrink: 0;
}
.emoji-tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 10px 8px;
  font-size: 13px;
  font-weight: 600;
  color: #707579;
  cursor: pointer;
}
.emoji-tab.active {
  color: #3390ec;
  box-shadow: inset 0 -2px 0 #3390ec;
}
.emoji-grids {
  flex: 1;
  min-height: 220px;
  max-height: 260px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}
.emoji-grid.emoji-grid-sections {
  display: block;
}
.emoji-section { margin-bottom: 10px; }
.emoji-section-title {
  font-size: 11px;
  font-weight: 600;
  color: #707579;
  padding: 2px 2px 6px;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.emoji-section-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}
.emoji-item-wide img { width: auto; max-width: 64px; height: 32px; object-fit: contain; }
.emoji-grid.hidden { display: none !important; }
.emoji-item-char {
  font-size: 28px;
  line-height: 1;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
.emoji-panel.hidden { display: none !important; }
.emoji-item {
  border: 0;
  background: transparent;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
}
.emoji-item:hover { background: var(--tg-hover); }
.emoji-item:active { background: var(--tg-active); transform: scale(0.94); }
.emoji-item img {
  width: 32px;
  height: 32px;
  display: block;
  pointer-events: none;
}
.bubble .text .msg-emoji {
  width: 1.25em;
  height: 1.25em;
  vertical-align: -0.2em;
  margin: 0 1px;
  display: inline-block;
}
.bubble .text .msg-icq {
  width: 20px;
  height: 20px;
}
.bubble .text .msg-kolobok {
  width: auto;
  max-width: 120px;
  height: auto;
  max-height: 32px;
  vertical-align: middle;
}
.tg-composer { position: relative; }

/* Context menu */
.msg-ctx {
  position: fixed;
  z-index: 50;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
  overflow: hidden;
  min-width: 180px;
  padding: 6px 0;
}

.msg-ctx button {
  display: block;
  width: 100%;
  border: 0;
  background: #fff;
  padding: 11px 20px;
  text-align: left;
  font-size: 15px;
  cursor: pointer;
  color: var(--tg-text);
}

.msg-ctx button.danger { color: var(--danger); }
.msg-ctx button:hover { background: var(--tg-hover); }

/* Reply bar */
.reply-bar {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin: 0 10px 6px;
  padding: 8px 10px 8px 0;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  border: 1px solid var(--tg-border);
}
.reply-bar.hidden { display: none !important; }
.reply-bar-accent {
  width: 3px;
  border-radius: 3px;
  background: var(--blue);
  flex-shrink: 0;
}
.reply-bar-body { flex: 1; min-width: 0; }
.reply-bar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 2px;
}
.reply-bar-preview {
  font-size: 13px;
  color: var(--tg-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-bar-close {
  border: 0;
  background: transparent;
  color: var(--tg-text-secondary);
  font-size: 18px;
  width: 32px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Reply quote in bubble */
.reply-quote {
  display: block;
  width: 100%;
  border: 0;
  border-left: 3px solid var(--blue);
  background: rgba(51, 144, 236, 0.08);
  border-radius: 8px;
  padding: 5px 8px;
  margin: 2px 2px 6px;
  text-align: left;
  cursor: pointer;
}
.bubble.out .reply-quote {
  border-left-color: #4fae4e;
  background: rgba(79, 174, 78, 0.12);
}
.reply-quote-name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 1px;
}
.bubble.out .reply-quote-name { color: #3d8b3c; }
.reply-quote-text {
  display: block;
  font-size: 12px;
  color: var(--tg-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble-row.msg-highlight .bubble {
  animation: socium-msg-flash 1.2s ease;
}
@keyframes socium-msg-flash {
  0%, 100% { filter: none; }
  30% { filter: brightness(0.92); box-shadow: 0 0 0 2px rgba(51, 144, 236, 0.35); }
}

/* Forward picker */
.forward-chat-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 60vh;
  overflow-y: auto;
}
.forward-chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: #fff;
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}
.forward-chat-item:hover { background: var(--tg-hover); }
.forward-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
.forward-chat-meta strong { font-size: 15px; }

/* Toast for copy/forward actions */
.socium-action-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom, 0px));
  transform: translateX(-50%) translateY(12px);
  background: rgba(0,0,0,.82);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.socium-action-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.chat-item.hidden-by-search { display: none !important; }

/* ── Drawer (hamburger menu) ── */
.drawer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 20;
  opacity: 1;
  transition: opacity 0.2s;
}

.drawer-overlay.hidden {
  display: none !important;
  opacity: 0;
  pointer-events: none;
}

.tg-drawer {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: #fff;
  z-index: 25;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 2px 0 12px rgba(0,0,0,.12);
  padding-top: var(--safe-top);
}

.tg-drawer.closed {
  transform: translateX(-105%);
  pointer-events: none;
}

.drawer-profile {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 18px 24px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
}

.drawer-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 500;
  flex-shrink: 0;
}

.drawer-profile-name { font-size: 17px; font-weight: 500; }
.drawer-profile-login { font-size: 14px; opacity: 0.85; margin-top: 2px; }

.drawer-nav { flex: 1; overflow-y: auto; padding: 8px 0; }

.drawer-item {
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 14px 22px;
  font-size: 15px;
  color: var(--tg-text);
  cursor: pointer;
  text-align: left;
}

.drawer-item:hover { background: var(--tg-hover); }
.drawer-item svg { color: var(--tg-text-secondary); flex-shrink: 0; }
.drawer-item.danger { color: var(--danger); }

/* Settings panel */
#screen-settings.settings-panel {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: #fff;
  display: none;
  flex-direction: column;
}

#screen-settings.settings-panel.active { display: flex; }

#screen-settings .topbar {
  background: #fff;
  color: var(--tg-text);
  border-bottom: 1px solid var(--tg-border);
}

#screen-settings .topbar .icon-btn { color: var(--tg-text-secondary); }
#screen-settings .topbar h1 { font-size: 17px; font-weight: 500; }

/* Responsive */
@media (min-width: 769px) {
  .tg-sidebar { width: var(--tg-sidebar-w); max-width: 33vw; }
  #back-btn { display: none !important; }
  .chat-empty { display: flex !important; }
  .tg-app.chat-open .chat-empty,
  .tg-main.chat-active .chat-empty { display: none !important; }
  .tg-main.chat-active .chat-pane { display: flex !important; flex: 1; min-height: 0; }
}

@media (max-width: 768px) {
  .tg-sidebar { max-width: 100%; width: 100%; }
  .tg-app:not(.chat-open) .tg-main { display: none !important; }
  .tg-app.chat-open .tg-sidebar { display: none !important; }
  .tg-app.chat-open .tg-main {
    display: flex !important;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 0;
    height: 100%;
  }
  .tg-app.chat-open .chat-pane {
    display: flex !important;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
  }
  .tg-app.chat-open .chat-empty { display: none !important; }
  .chat-empty { display: none !important; }
  .tg-drawer { width: min(300px, 90vw); }
}

/* In-app message alert (foreground) */
.socium-toast {
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: 12px;
  right: 12px;
  z-index: 9999;
  pointer-events: auto;
  animation: socium-toast-in 0.25s ease;
}
.socium-toast.hidden { display: none !important; }
.socium-toast-inner {
  background: #fff;
  border-left: 4px solid var(--blue);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  cursor: pointer;
}
.socium-toast-inner strong {
  display: block;
  font-size: 14px;
  color: var(--blue);
  margin-bottom: 2px;
}
.socium-toast-inner span {
  display: block;
  font-size: 15px;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@keyframes socium-toast-in {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

.attach-preview {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  margin-bottom: 6px;
  background: var(--tg-composer-bg, #fff);
  border: 1px solid var(--tg-border, #e0e0e0);
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
  z-index: 30;
}
.attach-preview.hidden { display: none !important; }
.attach-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 14px;
}
.attach-preview-close {
  border: 0;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
}
.attach-preview-media {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 180px;
  overflow: auto;
  margin-bottom: 8px;
}
.attach-preview-media img,
.attach-preview-media video {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  background: #f0f0f0;
}
.attach-preview-more {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  font-weight: 600;
}
.attach-preview-file {
  font-size: 13px;
  color: var(--tg-text-secondary);
  margin-bottom: 8px;
  word-break: break-word;
}
.attach-preview-file.hidden { display: none !important; }
#attach-preview-caption {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--tg-border, #e0e0e0);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  resize: none;
  margin-bottom: 8px;
}
.attach-preview-send { width: 100%; }

.msg-select-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--tg-header-bg, #fff);
  border-bottom: 1px solid var(--tg-border, #e0e0e0);
}
.msg-select-bar.hidden { display: none !important; }
.msg-select-bar #msg-select-count { flex: 1; font-weight: 600; }
.msg-select-bar .danger { color: var(--danger, #e53935); }

.messages.selection-mode .bubble-row {
  position: relative;
  padding-left: 36px;
}
.messages.selection-mode .bubble-row::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border: 2px solid var(--blue);
  border-radius: 50%;
  box-sizing: border-box;
}
.messages.selection-mode .bubble-row.selected::before {
  background: var(--blue);
  box-shadow: inset 0 0 0 3px #fff;
}
.tg-composer { position: relative; }
