/* ═══════════════════════════════════════════════════════════
   Telegram Liquid Glass UI — CSS
   Source values from web.telegram.org/a/ (main.c5e86023.css)
   ═══════════════════════════════════════════════════════════ */

@font-face {
  font-family: "tg-icons";
  src: url("fonts/tg-icons.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: block;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, a, input, [role="button"] { -webkit-tap-highlight-color: transparent; }

:root {
  /* Telegram Web A design tokens */
  --primary: #3390ec;
  --primary-light: rgba(51,144,236,0.12);
  /* Outgoing bubble (overridden per-theme by JS) */
  --own-bubble: rgba(200,232,175,0.85);
  --own-meta: rgba(82,154,68,0.7);
  --other-bubble-light: rgba(255,255,255,0.85);
  --other-bubble-dark: rgba(33,33,33,0.85);
  --glass-light: rgba(255,255,255,0.733);
  --glass-dark: rgba(33,33,33,0.867);
  --bg-sidebar-light: #ffffff;
  --bg-sidebar-dark: #212121;
  --bg-secondary-light: #f4f4f5;
  --bg-secondary-dark: rgb(15,15,15);
  --bg-shell-light: #e4e4e5;
  --bg-shell-dark: #0e1621;
  --hover-light: #f4f4f5;
  --hover-dark: rgba(255,255,255,0.06);
  --sep-light: rgba(0,0,0,0.06);
  --sep-dark: rgba(255,255,255,0.08);
  --text-light: #000000;
  --text-dark: #ffffff;
  --text-secondary-light: rgba(0,0,0,0.45);
  --text-secondary-dark: rgba(255,255,255,0.5);
  --shadow-light: rgba(114,114,114,0.25);
  --shadow-dark: rgba(16,16,16,0.612);
  --header-height: 3.5rem;
  --bubble-radius: 1rem;
  --bubble-tail: 0.5rem;
  --message-text-size: 1rem;
  --msg-container-width: 45.5rem;
  --sidebar-width: clamp(280px, 30%, 420px);
  --menu-min-width: 13.5rem;
  --blur-glass: blur(10px);
  --blur-bubble: blur(4px);
  --menu-animation: menuIn 150ms cubic-bezier(0.2, 0, 0.2, 1);

  /* Active theme (toggled by body.dark) */
  --tc: var(--text-light);
  --ts: var(--text-secondary-light);
  --sbg: var(--bg-sidebar-light);
  --shell: var(--bg-shell-light);
  --hover: var(--hover-light);
  --sep: var(--sep-light);
  --glass-bg: var(--glass-light);
  --other-bubble: var(--other-bubble-light);
  --shadow: var(--shadow-light);
  --own-meta-unread: rgba(0,0,0,0.25);
  --active-chat-bg: var(--primary-light);
  --bg2: var(--bg-secondary-light);
  --island-bg: var(--bg-sidebar-light);
}

body.dark {
  --tc: var(--text-dark);
  --ts: var(--text-secondary-dark);
  --sbg: var(--bg-sidebar-dark);
  --shell: var(--bg-shell-dark);
  --hover: var(--hover-dark);
  --sep: var(--sep-dark);
  --glass-bg: var(--glass-dark);
  --other-bubble: var(--other-bubble-dark);
  --shadow: var(--shadow-dark);
  --own-meta-unread: rgba(255,255,255,0.35);
  --active-chat-bg: rgba(118,106,200,0.3);
  --bg2: var(--bg-secondary-dark);
  --island-bg: var(--bg-sidebar-dark);
}

body {
  font-family: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--tc);
  background: var(--shell);
  overflow: hidden;
  height: 100dvh;
  width: 100%;
}

.tg-icon {
  font-family: "tg-icons";
  font-style: normal;
  font-weight: normal;
  font-size: 24px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ── */
.app {
  display: flex;
  height: 100dvh;
  width: 100%;
  position: relative;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--sbg);
  border-right: 0.5px solid var(--sep);
  position: relative;
  z-index: 20;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 4px;
  min-height: 56px;
  flex-shrink: 0;
}
.sidebar-header .menu-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  border-radius: 50%; flex-shrink: 0; color: var(--ts);
}

/* ── Animated menu icon (hamburger ↔ back arrow morph) ── */
.sidebar-header .menu-btn {
  transition: width 300ms cubic-bezier(0.33,1,0.68,1);
  overflow: hidden;
}
.sidebar-header .menu-btn .animated-menu-icon {
  position: relative; display: block;
  width: 1.125rem; height: 0.125rem;
  border-radius: 0.125rem;
  background: var(--ts);
  transition: transform 0.25s;
}
.sidebar-header .menu-btn .animated-menu-icon::before,
.sidebar-header .menu-btn .animated-menu-icon::after {
  content: ""; position: absolute; left: 0;
  width: 1.125rem; height: 0.125rem;
  border-radius: 0.125rem;
  background: var(--ts);
  transition: transform 0.25s;
}
.sidebar-header .menu-btn .animated-menu-icon::before { top: -0.3125rem; }
.sidebar-header .menu-btn .animated-menu-icon::after  { top:  0.3125rem; }
.sidebar-header .menu-btn .animated-menu-icon.state-back {
  transform: rotate(180deg);
}
.sidebar-header .menu-btn .animated-menu-icon.state-back::before {
  transform: rotate(45deg) scaleX(0.75) translate(0.375rem, -0.1875rem);
}
.sidebar-header .menu-btn .animated-menu-icon.state-back::after {
  transform: rotate(-45deg) scaleX(0.75) translate(0.375rem, 0.1875rem);
}

/* SearchInput — matches Telegram Web A */
.search-bar {
  flex: 1; display: flex; align-items: center;
  border: 2px solid var(--hover); border-radius: 1.375rem;
  padding-right: 0.1875rem; height: 2.5rem;
  background: var(--hover); color: rgba(112,117,121,0.5);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.search-bar.has-focus {
  border-color: var(--primary);
  background: var(--sbg);
}
/* Search icon — stays visible, color transitions on focus */
.search-bar .icon-container-left {
  flex-shrink: 0; width: 1.5rem; margin-left: 0.75rem;
  display: flex; align-items: center; justify-content: center;
}
.search-bar .icon-container-left .tg-icon {
  font-size: 1.5rem; line-height: 1;
  color: var(--ts);
  transition: color 0.15s ease;
}
.search-bar.has-focus .icon-container-left .tg-icon { color: var(--primary); }
.search-bar input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--tc); font-size: 1rem; font-family: inherit;
  height: 2.5rem;
  padding: 0.4375rem 0.625rem 0.5rem 0.75rem;
}
.search-bar input::placeholder { color: var(--ts); }
.search-bar .tg-icon { font-size: 1.25rem; color: var(--ts); flex-shrink: 0; }
.search-bar .search-clear-btn {
  flex-shrink: 0; width: 2.5rem; height: 2.5rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; color: var(--ts);
  font-size: 1rem;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease;
}
.search-bar.has-value .search-clear-btn { opacity: 1; pointer-events: auto; }

/* ── Sidebar Search Results ── */
.search-results {
  display: none; flex-direction: column;
  position: absolute; top: 3.5rem; left: 0; right: 0; bottom: 0;
  background: var(--sbg); z-index: 80; overflow: hidden;
}
.search-results.open { display: flex; }

.top-peers-section { padding: 0.5rem 1rem; }
.search-recent-contacts {
  overflow-x: auto; overflow-y: hidden;
  height: 6rem; margin: 0 -1rem; padding: 0 0.5rem;
  white-space: nowrap; flex-shrink: 0;
  scrollbar-width: none; scrollbar-color: transparent transparent;
}
.search-recent-contacts::-webkit-scrollbar { height: 0; }
.search-recent-contacts::-webkit-scrollbar-thumb { background-color: transparent; }
.search-recent-contact {
  display: inline-flex; flex-direction: column; align-items: center;
  width: 4.5rem; height: 6rem;
  padding: 0.625rem 0.25rem;
  border-radius: 0.5rem; cursor: pointer;
  margin-left: 0.5rem; vertical-align: top;
}
.search-recent-contact:first-child { margin-left: 0.5rem; }
.search-recent-contact:last-child { margin-right: 0.125rem; }
.search-recent-contact:hover { background: var(--hover); }
.search-recent-contact .contact-avatar {
  width: 3rem; height: 3rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 1rem;
  margin-bottom: 0.375rem; position: relative;
}
.search-recent-contact .contact-avatar .online-dot {
  position: absolute; bottom: 0; right: 0;
  width: 0.75rem; height: 0.75rem; border-radius: 50%;
  background: #4dcd5e; border: 2px solid var(--sbg);
}
.search-recent-contact .contact-name {
  font-size: 0.75rem; text-align: center;
  overflow: hidden; text-overflow: ellipsis; width: 100%;
  color: var(--tc);
}

.search-section-heading {
  padding: 0.625rem 1rem 0.375rem;
  font-size: 0.875rem; font-weight: 500;
  color: var(--ts);
}

.search-chat-results {
  flex: 1; overflow-y: auto; padding: 0 0.5rem;
}
.search-chat-result {
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0.375rem 0.5rem; border-radius: 0.625rem;
  cursor: pointer; transition: background 150ms;
}
.search-chat-result:hover { background: var(--hover); }
.search-chat-result .result-avatar {
  width: 3rem; height: 3rem; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 1.125rem;
}
.search-chat-result .result-info { flex: 1; min-width: 0; }
.search-chat-result .result-name {
  font-size: 1rem; font-weight: 500; line-height: 1.6875rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-chat-result .result-subtitle {
  font-size: 0.875rem; color: var(--ts);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  line-height: 1.25rem;
}
.search-highlight {
  display: inline; padding: 0 0.125rem; border-radius: 0.25rem;
  background: #cae3f7; color: var(--tc);
}
body.dark .search-highlight { background: color-mix(in srgb, var(--primary) 27%, transparent); }

.search-no-results {
  display: flex; align-items: center; justify-content: center;
  padding: 2rem; color: var(--ts); font-size: 1rem;
}

/* ── Middle Search (in-chat search) ── */
.middle-search {
  position: absolute; z-index: 100;
  top: 0; left: 0; right: 0;
  height: 3.5rem;
  display: flex; align-items: center;
  padding: 0 0.5rem;
  background: var(--sbg);
  opacity: 0; pointer-events: none;
  transition: opacity 200ms ease-in-out;
}
.middle-search.active {
  opacity: 1; pointer-events: auto;
}
.middle-search .middle-search-input {
  flex: 1; margin: 0 0.25rem;
}
.middle-search .middle-search-input .search-bar { width: 100%; }
.middle-search-close {
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--ts); flex-shrink: 0;
}
.middle-search-close:hover { background: var(--hover); }

/* In-chat search footer bar */
.middle-search-footer {
  position: absolute; z-index: 100;
  bottom: 0; left: 0; right: 0;
  height: 3.5rem;
  display: flex; align-items: center;
  padding: 0 0.5rem 0 1rem;
  background: var(--sbg);
  box-shadow: 0 -2px 2px rgba(0,0,0,0.06);
  opacity: 0; pointer-events: none;
  transition: opacity 200ms ease-in-out, transform 200ms ease-in-out;
  transform: translateY(100%);
}
.middle-search-footer.active {
  opacity: 1; pointer-events: auto; transform: translateY(0);
}
.middle-search-counter {
  flex: 1; font-size: 0.9375rem; color: var(--ts);
}
.middle-search-nav {
  display: flex; align-items: center; gap: 0.25rem;
}
.middle-search-nav button {
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--ts); transition: background 150ms;
}
.middle-search-nav button:hover { background: var(--hover); }
.middle-search-nav button:disabled { opacity: 0.3; cursor: default; }
.middle-search-nav button:disabled:hover { background: none; }

/* Highlighted message in search */
.bubble.search-match { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 1rem; }
.bubble.search-current { background: rgba(51,144,236,0.15) !important; }

/* Chat list */
.chat-list { flex: 1; overflow-y: auto; padding: 0 4px; }

.chat-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px; background: transparent; border: none; cursor: pointer;
  border-radius: 10px; transition: background 150ms;
  text-align: left; font-family: inherit; color: inherit;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active-chat-bg); }
.chat-item.active:hover { background: var(--active-chat-bg); }

.chat-avatar {
  width: 54px; height: 54px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 22px; position: relative;
}
.chat-avatar .online-dot {
  position: absolute; bottom: 0; right: 0;
  width: 14px; height: 14px; border-radius: 50%;
  background: #4dcd5e; border: 2px solid var(--sbg);
}

.chat-info { flex: 1; min-width: 0; }
.chat-info .top-row { display: flex; align-items: center; gap: 4px; }
.chat-name {
  flex: 1; font-weight: 500; font-size: 15px; line-height: 20px;
  color: var(--tc); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-time { font-size: 12px; flex-shrink: 0; }
.chat-time.has-unread { color: var(--primary); }
.chat-time:not(.has-unread) { color: var(--ts); }

.chat-preview { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.chat-last-msg {
  flex: 1; font-size: 14px; line-height: 18px; color: var(--ts);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-badge {
  min-width: 22px; height: 22px; border-radius: 11px;
  font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px; flex-shrink: 0; color: #fff; background: var(--primary);
}
.chat-badge.muted { background: rgba(128,128,128,0.25); color: var(--ts); }
.pinned-icon { font-size: 18px; color: var(--ts); flex-shrink: 0; }

/* FAB */
.fab {
  position: absolute; bottom: 24px; right: 24px;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2); z-index: 10; color: #fff;
}

/* ── Chat Panel ── */
.chat-panel {
  flex: 1; display: flex; flex-direction: column;
  position: relative; overflow: hidden; min-width: 0;
}

/* Wallpaper */
.wallpaper { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.wallpaper canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: auto; }
.wallpaper .pattern-overlay {
  position: absolute; inset: 0;
  background-repeat: repeat; background-size: 420px auto;
  mix-blend-mode: overlay; pointer-events: none;
}

/* Glass */
.glass {
  background: var(--glass-bg);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
}

/* Chat header */
/* Chat Header — matches Telegram Web A MiddleHeader */
.chat-header {
  position: relative; z-index: 50;
  display: flex; align-items: center;
  padding: 0.25rem max(0.8125rem, env(safe-area-inset-right)) 0.25rem max(0.5rem, env(safe-area-inset-left));
  height: 3.5rem; flex-shrink: 0;
  background: var(--sbg);
}
.chat-header .header-avatar {
  width: 2.5rem; height: 2.5rem; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 1.0625rem;
  margin-right: 0.625rem;
}
.chat-header .header-info {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; justify-content: center;
}
.chat-header .header-name {
  font-weight: 500; font-size: 1.125rem; line-height: 1.5rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-header .header-status {
  font-size: 0.875rem; line-height: 1.125rem; color: var(--ts);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-header .header-status.online { color: var(--primary); }
.chat-header .header-actions {
  display: flex; align-items: center; flex-shrink: 0; margin-left: auto;
}
.chat-header .header-actions button {
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--ts); transition: background 150ms;
  margin-left: 0.25rem;
}
.chat-header .header-actions button:hover { background: var(--hover); }
.chat-header .header-actions button .tg-icon { font-size: 1.5rem; }
.chat-header .header-actions button.active .tg-icon { color: var(--primary); }

.mobile-back {
  background: none; border: none; cursor: pointer;
  padding: 4px; display: none; color: var(--primary);
}

/* Messages */
.messages {
  flex: 1; position: relative; z-index: 1;
  overflow-y: auto; padding: 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.date-divider { display: flex; justify-content: center; margin: 8px 0 12px; }
.date-pill { padding: 4px 12px; border-radius: 20px; font-size: 13px; font-weight: 500; color: var(--ts); }

.msg-row {
  display: flex; padding: 1px 0;
  max-width: var(--msg-container-width); align-self: center; width: 100%;
}
.msg-row.own { justify-content: flex-end; }
.msg-row.other { justify-content: flex-start; }

.bubble {
  max-width: min(80%, 29rem); padding: 0.3125rem 0.5rem 0.375rem;
  border-radius: var(--bubble-radius);
  font-size: var(--message-text-size, 1rem);
  backdrop-filter: var(--blur-bubble);
  -webkit-backdrop-filter: var(--blur-bubble);
}
.msg-row.own .bubble {
  background: var(--own-bubble);
  border-bottom-right-radius: var(--bubble-tail);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
body.dark .msg-row.own .bubble { box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.msg-row.other .bubble {
  background: var(--other-bubble);
  border-bottom-left-radius: var(--bubble-tail);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
body.dark .msg-row.other .bubble { box-shadow: 0 1px 2px rgba(0,0,0,0.3); }

.bubble .text {
  font-size: var(--message-text-size, 1rem); line-height: 1.3125;
  color: var(--tc); unicode-bidi: plaintext; white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble .meta {
  position: relative; top: 0.375rem;
  float: right; margin-left: 0.4375rem; margin-right: -0.375rem;
  height: 1rem;
  font-size: 0.75rem; line-height: 1.35; white-space: nowrap;
  user-select: none; color: var(--ts);
}
.msg-row.own .bubble .meta { color: var(--own-meta); }
.bubble .meta .tg-icon { font-size: 16px; margin-left: 2px; vertical-align: middle; }
.bubble .meta .tg-icon.read { color: var(--own-meta); }
.bubble .meta .tg-icon.unread { color: var(--own-meta-unread); }

/* Composer — matches Telegram Web A Composer */
.composer {
  position: relative; z-index: 50;
  display: flex; align-items: flex-end;
  padding: 0.375rem 0.5rem;
  background: var(--sbg);
}
.composer-wrapper {
  position: relative; z-index: 1;
  flex: 1; display: flex; align-items: flex-end;
  min-height: 3rem;
  border-radius: 1rem; border-bottom-right-radius: 0;
  background: var(--sbg);
  box-shadow: 0 1px 2px rgba(114,114,114,0.25);
}
body.dark .composer-wrapper { box-shadow: 0 1px 2px rgba(16,16,16,0.6); }

/* SVG appendix tail (bottom-right) */
.composer-wrapper .svg-appendix {
  position: absolute; right: -0.5rem; bottom: -0.1875rem;
  width: 0.5625rem; height: 1.25rem;
  pointer-events: none;
}
.composer-wrapper .svg-appendix .corner { fill: var(--sbg); }

/* Emoji / Symbol button on left */
.composer-symbol-btn {
  width: 2.875rem; height: 2.875rem; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: rgba(112,117,121,0.8); font-size: 1.5rem;
  align-self: flex-end;
}
body.dark .composer-symbol-btn { color: rgba(170,170,170,0.8); }
.composer-symbol-btn:hover { color: var(--primary); }

/* Message input area */
.composer-input-area {
  flex: 1; display: flex; align-items: center;
  min-height: 3rem; position: relative;
}
.composer-input-area input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--tc); font-size: 1rem; font-family: inherit;
  line-height: 1.3125; padding: 0;
  height: auto;
}
.composer-input-area input::placeholder {
  color: var(--ts); opacity: 0.6;
}

/* Attach button (right side, inside wrapper) */
.composer-attach-btn {
  width: 3rem; height: 3rem; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: rgba(112,117,121,0.8); font-size: 1.5rem;
  align-self: flex-end;
}
body.dark .composer-attach-btn { color: rgba(170,170,170,0.8); }
.composer-attach-btn:hover { color: var(--primary); }
.composer-attach-btn .tg-icon { transform: rotate(45deg); }

/* Send / Mic button — outside composer wrapper */
.composer-send-btn {
  width: 3rem; height: 3rem; border-radius: 50%;
  background: var(--primary); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: #fff; margin-left: 0.5rem;
  transition: background-color 150ms;
}
.composer-send-btn:hover { filter: brightness(1.1); }

/* ── Theme Picker (in chat header) ── */
.settings-panel {
  position: relative; z-index: 50;
  padding: 8px 12px; border-bottom: 0.5px solid var(--sep);
  max-height: 220px; overflow-y: auto; display: none;
}
.settings-panel.open { display: block; }
.settings-panel .panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.settings-panel .panel-header span { font-size: 13px; font-weight: 600; }
.settings-panel .panel-header button { background: none; border: none; cursor: pointer; color: var(--ts); }

.pill-row { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.pill {
  padding: 3px 10px; border-radius: 8px; font-size: 11px; font-weight: 500;
  cursor: pointer; border: 1px solid transparent; font-family: inherit;
  white-space: nowrap; color: var(--tc); background: var(--hover);
}
.pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pill .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.pattern-pill { padding: 2px 8px; border-radius: 6px; font-size: 10px; }

.opacity-row { display: flex; align-items: center; gap: 8px; }
.opacity-row span { font-size: 11px; color: var(--ts); white-space: nowrap; }
.opacity-row input[type="range"] { flex: 1; accent-color: var(--primary); }
.opacity-row .val { width: 28px; }
.section-label { font-size: 13px; font-weight: 600; margin-bottom: 4px; }

/* ── Context Menu ── */
.context-menu {
  position: fixed; z-index: 200; min-width: var(--menu-min-width);
  padding: 8px 0; border-radius: 1rem; border: 0.5px solid var(--sep);
  box-shadow: 0 4px 8px 2px var(--shadow); animation: var(--menu-animation);
}
.context-menu button {
  width: 100%; display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; background: none; border: none; cursor: pointer;
  color: var(--tc); font-size: 15px; font-family: inherit; transition: background 150ms;
}
.context-menu button:hover { background: var(--hover); }
.context-menu button .tg-icon { font-size: 22px; color: var(--ts); flex-shrink: 0; }
.context-menu button.danger { color: #e53935; }
.context-menu button.danger .tg-icon { color: #e53935; }

/* ── Emoji Panel ── */
.emoji-panel {
  position: absolute; bottom: 60px; left: 8px; right: 8px;
  max-width: 420px; height: 240px; z-index: 60;
  border-radius: 16px; display: none; flex-direction: column; overflow: hidden;
}
.emoji-panel.open { display: flex; }
.emoji-tabs { display: flex; border-bottom: 0.5px solid var(--sep); padding: 0 4px; }
.emoji-tabs button {
  flex: 1; padding: 10px 0; background: none; border: none;
  border-bottom: 2px solid transparent; cursor: pointer; color: var(--ts);
}
.emoji-tabs button.active { border-bottom-color: var(--primary); color: var(--primary); }
.emoji-grid {
  flex: 1; overflow-y: auto; padding: 8px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.emoji-grid button { background: none; border: none; font-size: 24px; cursor: pointer; padding: 2px; border-radius: 8px; line-height: 1; }

/* ── Desktop Popup Menu (hamburger dropdown) ── */
.menu-popup-overlay {
  position: fixed; inset: 0; z-index: 100;
}
.menu-popup {
  position: absolute; top: 48px; left: 8px; z-index: 101;
  background: var(--sbg); border-radius: 1rem;
  box-shadow: 0 0.25rem 0.5rem 0.125rem rgba(0,0,0,0.12);
  min-width: 13.5rem; max-width: 20rem; padding: 0.5rem 0;
  transform-origin: top left;
  transform: scale(0.85); opacity: 0;
  transition: opacity 150ms cubic-bezier(0.2,0,0.2,1), transform 150ms cubic-bezier(0.2,0,0.2,1);
  overflow-y: auto; max-height: calc(100vh - 3.75rem);
}
.menu-popup.open { transform: scale(1); opacity: 1; }
.menu-popup.closing {
  transform: scale(0.85); opacity: 0;
  transition: opacity 200ms ease-in, transform 200ms ease-in;
}
/* Account header in popup */
.menu-popup .popup-account {
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0.5rem 0.875rem; cursor: pointer;
}
.menu-popup .popup-account:hover { background: var(--hover); }
.menu-popup .popup-account .popup-avatar {
  width: 2.25rem; height: 2.25rem; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9375rem; font-weight: 500; flex-shrink: 0;
}
.menu-popup .popup-account .popup-name {
  font-size: 0.9375rem; font-weight: 500; color: var(--tc);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.menu-popup .popup-sep {
  height: 0.5px; background: var(--sep); margin: 0.25rem 0;
}
.menu-popup .popup-item {
  display: flex; align-items: center; width: 100%;
  padding: 0.5625rem 0.875rem; border: none; background: none;
  color: var(--tc); font-size: 0.9375rem; line-height: 1.25rem;
  cursor: pointer; white-space: nowrap; -webkit-tap-highlight-color: transparent;
  gap: 0;
}
.menu-popup .popup-item:hover { background: var(--hover); }
.menu-popup .popup-item .tg-icon {
  font-size: 1.375rem; color: var(--ts); width: 1.5rem; text-align: center;
  margin-right: 1.125rem; flex-shrink: 0;
}
.menu-popup .popup-item .item-label { flex: 1; text-align: left; }
.menu-popup .popup-item .right-badge {
  min-width: 1.25rem; height: 1.25rem; padding: 0 0.375rem;
  border-radius: 0.625rem; font-size: 0.75rem; font-weight: 600;
  line-height: 1.25rem; color: #fff; background: #a8a8a8; text-align: center;
  margin-left: 0.375rem;
}
.menu-popup .popup-item .toggle-track { margin-left: auto; }
.menu-popup .popup-item .submenu-arrow {
  margin-left: auto; color: var(--ts);
}
.menu-popup .popup-item .submenu-arrow .tg-icon {
  font-size: 1rem; margin-right: 0;
}
.menu-popup .popup-footer {
  padding: 0.375rem 0.5rem; font-size: 0.6875rem; line-height: 1.25;
  color: var(--ts); text-align: center; background: var(--hover);
  border-radius: 0 0 1rem 1rem;
}
/* ── My Profile Panel (matches Telegram Web A latest right-column Profile) ── */
.profile-menu {
  position: absolute; inset: 0; z-index: 110;
  background: var(--bg2);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 250ms cubic-bezier(0.25, 1, 0.5, 1),
              visibility 0s linear 250ms;
}
.profile-menu.open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 250ms cubic-bezier(0.25, 1, 0.5, 1),
              visibility 0s linear 0s;
}

/* Profile header — sticky top bar */
.profile-header {
  display: flex; align-items: center;
  padding: 0 8px; min-height: 3.5rem; flex-shrink: 0;
  position: relative; z-index: 10;
  background: var(--bg2);
}
.profile-header-title {
  font-weight: 600; font-size: 17px; color: var(--tc);
  position: absolute; left: 56px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; will-change: opacity; opacity: 0;
}

/* Profile body — scrollable */
.profile-body {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* Floating morph avatar (absolute in .profile-menu, driven by JS) */
.profile-morph-avatar {
  position: absolute; z-index: 12;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500;
  will-change: transform;
  pointer-events: none;
  transform-origin: center center;
}

/* ProfileInfo section — ghost spacer + name + status */
.profile-info-block {
  background: var(--bg2);
  display: flex; flex-direction: column; align-items: center;
  padding: 1rem 1.5rem 0.5rem;
}
.profile-avatar-ghost {
  width: 7.5rem; height: 7.5rem; border-radius: 50%;
  flex-shrink: 0; visibility: hidden;
}
.profile-user-info {
  text-align: center; will-change: opacity;
}
.profile-name {
  font-size: 1.125rem; font-weight: 600; color: var(--tc);
  text-align: center; margin-top: 1rem;
  line-height: 1.3;
}
.profile-status {
  font-size: 0.875rem; color: var(--ts); margin-top: 0.125rem;
}
.profile-status.online { color: var(--primary); }

/* ChatExtra — Island cards */
.profile-extra {
  padding: 1rem; padding-bottom: 0;
}
.profile-island {
  padding: 0.5rem;
  border-radius: 1.5rem;
  background: var(--island-bg);
  box-shadow: 0 1px 4px 0 rgba(0,0,0,0.05);
}
.profile-island + .profile-island {
  margin-top: 1rem;
}

/* ListItem rows inside islands */
.profile-list-item {
  position: relative;
  display: flex; align-items: center;
  min-height: 3rem;
  padding: 0 1rem;
  border: none; background: none; cursor: pointer;
  width: 100%; text-align: left;
  font-family: inherit; font-size: 1rem;
  color: var(--tc);
  border-radius: 0.75rem;
  transition: background 150ms;
}
.profile-list-item:hover { background: var(--hover); }
.profile-list-item:active { background: var(--hover); }
.profile-list-item.is-static { cursor: default; }
.profile-list-item.is-static:hover { background: none; }

.profile-list-item > .tg-icon {
  margin-right: 1.75rem;
  font-size: 1.5rem;
  color: var(--ts);
  flex-shrink: 0;
}

.profile-list-item .list-item-main {
  display: flex; flex-direction: column;
  min-width: 0; flex: 1;
  padding: 0.5rem 0;
}
.profile-list-item .list-item-title {
  font-size: 1rem; line-height: 1.3125;
  color: var(--tc);
  word-break: break-word; white-space: pre-wrap;
  overflow: hidden; text-overflow: ellipsis;
}
.profile-list-item .list-item-subtitle {
  font-size: 0.8125rem; color: var(--ts);
  margin-top: 0.0625rem; line-height: 1.25rem;
}

.profile-list-item .toggle-track {
  margin-left: auto; flex-shrink: 0;
}

/* Shared Media Tabs — sticky within profile scroll */
.profile-shared-tabs {
  position: sticky; top: 0; z-index: 2;
  display: flex; gap: 0;
  margin: 1rem 1rem 0;
  background: transparent;
}
.profile-shared-tabs::before {
  content: ""; position: absolute; z-index: 0;
  top: -1rem; left: -1rem; right: -1rem; bottom: -0.5rem;
  background: linear-gradient(to bottom, var(--bg2) 0%, transparent 100%);
  backdrop-filter: blur(0.5rem);
  mask-image: linear-gradient(to bottom, black 65%, transparent 100%);
  pointer-events: none;
}
.profile-tab-btn {
  position: relative; z-index: 1;
  flex: 1; padding: 0.75rem 0;
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 0.8125rem; font-weight: 600;
  color: var(--ts); text-align: center;
  transition: color 200ms;
  border-bottom: 2px solid transparent;
}
.profile-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.profile-tab-btn:hover:not(.active) { color: var(--tc); }

/* Shared media grid placeholder */
.profile-media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px; margin: 1rem;
  border-radius: 1.5rem; overflow: hidden;
}
.profile-media-thumb {
  aspect-ratio: 1; background: var(--hover);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: var(--ts); opacity: 0.5;
}

/* Edit button in profile header */
.profile-edit-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  border-radius: 50%; color: var(--ts); z-index: 2;
  margin-left: auto;
}
.profile-edit-btn:hover { background: var(--hover); }

/* Theme transition — View Transitions API */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 250ms;
  animation-timing-function: cubic-bezier(0.33, 0, 0.2, 1);
}
/* Fallback overlay fade for unsupported browsers */
.theme-fade-overlay {
  position: fixed; inset: 0; z-index: 9999;
  pointer-events: none;
  animation: themeFadeOut 250ms cubic-bezier(0.33, 0, 0.2, 1) forwards;
}
@keyframes themeFadeOut { from { opacity: 1; } to { opacity: 0; } }

/* Hide popup on mobile */
@media (max-width: 768px) {
  .menu-popup, .menu-popup-overlay { display: none !important; }
}

/* ── Drawer (mobile only) ── */
.drawer-overlay {
  position: absolute; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none;
  transition: opacity 200ms cubic-bezier(0.2, 0, 0.2, 1);
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: absolute; top: 0; left: 0; bottom: 0;
  width: 85%; max-width: 360px; z-index: 101;
  background: var(--sbg); display: flex; flex-direction: column;
  box-shadow: 2px 0 16px rgba(0,0,0,0.15);
  transform: translateX(-100%);
  transition: transform 200ms cubic-bezier(0.2, 0, 0.2, 1);
}
.drawer.open { transform: translateX(0); }
/* Hide drawer on desktop */
@media (min-width: 769px) {
  .drawer, .drawer-overlay { display: none !important; }
}

.drawer-profile { padding: 16px 16px 12px; background: var(--hover); }
.drawer-profile .avatar {
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 22px; margin-bottom: 12px;
}
.drawer-profile .name { font-weight: 600; font-size: 16px; }
.drawer-profile .phone { font-size: 14px; color: var(--ts); margin-top: 2px; }
.drawer-items { flex: 1; overflow-y: auto; padding: 4px 0; }
.drawer-item {
  width: 100%; display: flex; align-items: center; gap: 20px;
  padding: 10px 20px; background: none; border: none; cursor: pointer;
  color: var(--tc); font-size: 15px; font-family: inherit; transition: background 150ms;
}
.drawer-item:hover { background: var(--hover); }
.drawer-item .tg-icon { font-size: 24px; color: var(--ts); width: 28px; }
.drawer-item .label { flex: 1; text-align: left; }
.drawer-item .toggle-track {
  width: 36px; height: 22px; border-radius: 11px;
  position: relative; transition: background 200ms; background: rgba(0,0,0,0.15);
}
body.dark .drawer-item .toggle-track { background: var(--primary); }
.drawer-item .toggle-track.on { background: var(--primary); }
.drawer-item .toggle-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  position: absolute; top: 2px; left: 2px;
  transition: left 200ms; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.drawer-item .toggle-track.on .toggle-thumb { left: 16px; }
.drawer-sep { border-bottom: 0.5px solid var(--sep); margin: 4px 0; }
.drawer-badge {
  min-width: 22px; height: 22px; border-radius: 11px;
  background: var(--hover); font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px; color: var(--ts);
}

/* ── Settings Menu (full page overlay on sidebar) ── */
.settings-menu {
  position: absolute; inset: 0; z-index: 110;
  background: var(--sbg);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 250ms cubic-bezier(0.25, 1, 0.5, 1),
              visibility 0s linear 250ms;
}
.settings-menu.open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 250ms cubic-bezier(0.25, 1, 0.5, 1),
              visibility 0s linear 0s;
}

.settings-menu-header {
  display: flex; align-items: center;
  padding: 0 8px; min-height: 56px; flex-shrink: 0;
  border-bottom: 0.5px solid var(--sep);
  position: relative; z-index: 10;
  background: var(--sbg);
}
.settings-back {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  border-radius: 50%; color: var(--primary); flex-shrink: 0;
  z-index: 2;
}
.settings-menu-title {
  font-weight: 600; font-size: 17px; color: var(--tc);
  position: absolute; left: 56px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; will-change: opacity;
}
/* Header name (appears during morph) */
.settings-header-name {
  font-weight: 600; font-size: 17px; color: var(--tc);
  position: absolute; left: 100px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; will-change: opacity; opacity: 0;
}
.settings-menu-spacer { flex: 1; }
.settings-edit-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  border-radius: 50%; color: var(--ts); z-index: 2;
}

/* Floating morph avatar — positioned absolutely in .settings-menu, driven by JS */
.settings-morph-avatar {
  position: absolute; z-index: 12;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500;
  will-change: transform;
  pointer-events: none;
  transform-origin: center center;
}

.settings-scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
/* Ghost spacer in scroll where the avatar would be */
.settings-profile {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 24px 16px 20px; border-bottom: 0.5px solid var(--sep);
  text-align: center;
}
.settings-avatar-ghost {
  width: 110px; height: 110px; border-radius: 50%; flex-shrink: 0;
  visibility: hidden; /* invisible spacer — real avatar is the floating morph */
}
.settings-user-info { min-width: 0; text-align: center; will-change: opacity, transform; }
.settings-user-name { font-weight: 600; font-size: 20px; line-height: 26px; }
.settings-user-phone { font-size: 14px; color: var(--ts); margin-top: 3px; }
.settings-user-username { font-size: 14px; color: var(--primary); margin-top: 2px; }

/* Spacer so content can scroll past the profile */
.settings-scroll-spacer { min-height: 50vh; flex-shrink: 0; }

.settings-sections { padding: 4px 0; border-bottom: 0.5px solid var(--sep); }
.settings-footer-links { padding: 4px 0; }

.settings-section-item {
  width: 100%; display: flex; align-items: center; gap: 20px;
  padding: 12px 20px; background: none; border: none; cursor: pointer;
  color: var(--tc); font-size: 15px; font-family: inherit;
  transition: background 150ms; text-align: left;
}
.settings-section-item:hover { background: var(--hover); }
.settings-section-item .tg-icon { font-size: 24px; color: var(--ts); width: 28px; flex-shrink: 0; }
.settings-section-label { flex: 1; }
.settings-section-value { font-size: 14px; color: var(--primary); flex-shrink: 0; }

.settings-version {
  padding: 16px 20px; font-size: 13px; color: var(--ts); text-align: center;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.3); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── Animations ── */
@keyframes menuIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar {
    width: 100% !important;
    position: absolute !important;
    inset: 0 !important;
    z-index: 30 !important;
    transition: transform 300ms cubic-bezier(0.25, 1, 0.5, 1);
  }
  .sidebar.mobile-chat {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .chat-panel {
    width: 100% !important;
    position: absolute !important;
    inset: 0 !important;
    transition: transform 300ms cubic-bezier(0.25, 1, 0.5, 1);
  }
  .chat-panel.mobile-sidebar {
    transform: translateX(100%);
  }

  .mobile-back { display: flex !important; }

  /* Prevent text selection on long-press (mobile context menu) */
  .bubble {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: pan-y;
  }
}

@media (min-width: 769px) {
  .sidebar, .chat-panel {
    transform: none !important;
    pointer-events: auto !important;
  }
}
