/* ==========================================================================
   Mithaq — premium messaging UI
   --------------------------------------------------------------------------
   A complete design system on top of Bulma's layout helpers. Every class name
   is kept stable so app.js works unchanged; this file only restyles the shell.
   ========================================================================== */

:root {
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-display: "Space Grotesk", "Inter", -apple-system, BlinkMacSystemFont,
               "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  --radius-full: 999px;

  /* Brand */
  --accent: #4f6bff;
  --accent-2: #7b5cff;
  --accent-strong: #3d55e6;
  --accent-soft: rgba(79, 107, 255, .12);
  --accent-glow: rgba(79, 107, 255, .38);
  --grad-accent: linear-gradient(135deg, #4f6bff 0%, #7b5cff 100%);
  --grad-accent-soft: linear-gradient(135deg, rgba(79,107,255,.14), rgba(123,92,255,.14));

  --online: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;

  --ease: cubic-bezier(.22, .61, .36, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-soft: cubic-bezier(.4, 0, .2, 1);

  /* Depth */
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 2px 8px rgba(16, 24, 40, .06);
  --shadow-md: 0 10px 30px rgba(16, 24, 40, .10);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, .16);
  --ring: 0 0 0 1px rgba(16, 24, 40, .06);
}

/* ============================ themes ============================ */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f7;
  --bg-deep: #e6eaf4;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --surface-glass: rgba(255, 255, 255, .78);
  --panel: #ffffff;
  --panel-2: #f7f8fc;
  --input-bg: #f0f2f8;
  --hover: #f3f4f9;
  --active: #eef1ff;
  --active-soft: rgba(79, 107, 255, .12);

  --bubble-in: #ffffff;
  --bubble-out: linear-gradient(135deg, #4f6bff 0%, #6b4ff0 100%);
  --bubble-in-border: #eceef5;

  --text: #0f1420;
  --text-secondary: #5b6472;
  --text-tertiary: #9aa3b2;

  --border: #e8eaf1;
  --border-strong: #dcdfe9;

  --mine-meta: rgba(255, 255, 255, .72);
  --theirs-meta: #8a93a3;

  --chat-bg: linear-gradient(180deg, #eef1f7 0%, #e8ecf5 100%);
  --chat-bg-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32'%3E%3Ccircle cx='2' cy='2' r='1' fill='%234f6bff' fill-opacity='0.05'/%3E%3C/svg%3E");

  --scrollbar: #c4c9d6;
  --glass-blur: blur(18px) saturate(1.5);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080b14;
  --bg-deep: #060810;
  --surface: #111624;
  --surface-2: #151b2d;
  --surface-glass: rgba(17, 22, 36, .72);
  --panel: #141a2b;
  --panel-2: #181f33;
  --input-bg: #1b2238;
  --hover: #1b2134;
  --active: #1f2740;
  --active-soft: rgba(99, 124, 255, .22);

  --bubble-in: #1a2138;
  --bubble-out: linear-gradient(135deg, #4f6bff 0%, #7b5cff 100%);
  --bubble-in-border: #222a45;

  --text: #f2f5fb;
  --text-secondary: #9aa4b8;
  --text-tertiary: #5f6a80;

  --border: #1d2438;
  --border-strong: #28304a;

  --mine-meta: rgba(255, 255, 255, .7);
  --theirs-meta: #7e89a0;

  --chat-bg: linear-gradient(180deg, #080b14 0%, #0b0f1d 100%);
  --chat-bg-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32'%3E%3Ccircle cx='2' cy='2' r='1' fill='%237b5cff' fill-opacity='0.06'/%3E%3C/svg%3E");

  --scrollbar: #2a3349;
  --glass-blur: blur(18px) saturate(1.3);
}

/* ============================ base ============================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .25s var(--ease), color .25s var(--ease);
  overscroll-behavior: none;
}

h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -.01em; }
button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; -webkit-tap-highlight-color: transparent; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }

::selection { background: var(--accent-soft); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 9px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.icon { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: middle; }
.icon svg { width: 100%; height: 100%; display: block; }
.icon--xs { width: 14px; height: 14px; }

/* ============================ buttons & inputs ============================ */
.tg-btn {
  height: 48px;
  padding: 0 20px;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14.5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--input-bg);
  color: var(--text);
  transition: background .18s var(--ease), transform .14s var(--spring), box-shadow .2s var(--ease), filter .18s var(--ease);
}
.tg-btn:hover:not(:disabled) { background: var(--hover); }
.tg-btn:active:not(:disabled) { transform: translateY(1px) scale(.985); }
.tg-btn:disabled { opacity: .5; cursor: not-allowed; }

.tg-btn--primary {
  background: var(--grad-accent);
  color: #fff;
  box-shadow: 0 6px 18px var(--accent-glow);
}
.tg-btn--primary:hover:not(:disabled) {
  background: var(--grad-accent);
  filter: brightness(1.06) saturate(1.05);
  box-shadow: 0 8px 24px var(--accent-glow);
}

.button.tg-btn { box-shadow: none; border: none; }
.button.tg-btn:focus, .button.tg-btn:hover { box-shadow: none; }
.button.tg-btn--primary { box-shadow: 0 6px 18px var(--accent-glow); }

.input.tg-input {
  background: var(--input-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text);
  box-shadow: none;
  height: 48px;
  font-size: 14.5px;
  transition: border .18s var(--ease), background .18s var(--ease), box-shadow .2s var(--ease);
}
.input.tg-input::placeholder { color: var(--text-tertiary); }
.input.tg-input:focus {
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.field .label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 7px; letter-spacing: .01em; }

.tg-icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  transition: background .15s var(--ease), color .15s var(--ease), transform .14s var(--spring);
}
.tg-icon-btn:hover { background: var(--hover); color: var(--text); }
.tg-icon-btn:active { transform: scale(.9); }
.tg-icon-btn .icon { width: 21px; height: 21px; }
.tg-icon-btn--accent {
  background: var(--grad-accent);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.tg-icon-btn--accent:hover { background: var(--grad-accent); color: #fff; filter: brightness(1.06); }

/* ============================ auth ============================ */
.tg-auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}
/* ambient gradient orbs */
.tg-auth::before,
.tg-auth::after {
  content: "";
  position: absolute;
  width: 60vmax;
  height: 60vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: .5;
  pointer-events: none;
}
.tg-auth::before {
  background: radial-gradient(circle, var(--accent) 0%, transparent 62%);
  top: -22vmax;
  right: -18vmax;
  animation: drift 22s var(--ease) infinite alternate;
}
.tg-auth::after {
  background: radial-gradient(circle, var(--accent-2) 0%, transparent 62%);
  bottom: -24vmax;
  left: -16vmax;
  animation: drift 26s var(--ease) infinite alternate-reverse;
}

.tg-auth__card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--surface-glass);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), var(--ring);
  padding: 40px 32px 34px;
  animation: rise .5s var(--spring);
}
.tg-auth__brand { display: flex; flex-direction: column; align-items: center; margin-bottom: 26px; }
.tg-auth__logo {
  width: 68px; height: 68px; border-radius: 20px;
  display: grid; place-items: center;
  background: var(--grad-accent);
  color: #fff;
  margin-bottom: 16px;
  box-shadow: 0 12px 30px var(--accent-glow);
  position: relative;
}
.tg-auth__logo::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 15px;
  background: linear-gradient(180deg, rgba(255,255,255,.28), transparent 55%);
  pointer-events: none;
}
.tg-auth__logo .icon { width: 32px; height: 32px; }
.tg-auth__title { font-size: 27px; font-weight: 700; color: var(--text); letter-spacing: -.02em; }
.tg-auth__subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 6px; text-align: center; }

.tg-tabs {
  display: flex;
  background: var(--input-bg);
  border-radius: var(--radius-full);
  padding: 4px;
  margin-bottom: 22px;
}
.tg-tab {
  flex: 1; padding: 9px; border-radius: var(--radius-full);
  font-weight: 600; font-size: 14px; color: var(--text-secondary);
  background: transparent; border: none;
  transition: all .22s var(--ease);
}
.tg-tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.tg-auth__error {
  background: rgba(239, 68, 68, .1);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, .28);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 18px;
  display: none;
  font-weight: 500;
}
.tg-auth__error.visible { display: block; animation: shake .35s var(--ease); }

.tg-auth__submit { width: 100%; height: 50px; border-radius: var(--radius-md); }
.tg-auth__hint {
  text-align: center; color: var(--text-tertiary); font-size: 12.5px;
  margin-top: 20px; line-height: 1.6;
}
.tg-auth__lock { display: inline-flex; align-items: center; gap: 6px; }
.tg-auth__lock .icon { width: 13px; height: 13px; }

/* ============================ shell ============================ */
.tg { display: flex; height: 100dvh; width: 100%; overflow: hidden; background: var(--bg); }

.tg-sidebar {
  flex: 0 0 30%;
  min-width: 300px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: 0;
  position: relative;
}

.tg-chat {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: var(--bg);
}

/* ---- sidebar header ---- */
.tg-sidebar__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 12px;
  flex: none;
}
.tg-search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  background: var(--input-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  padding: 0 15px;
  height: 44px;
  color: var(--text-tertiary);
  transition: border .18s var(--ease), background .18s var(--ease), box-shadow .2s var(--ease);
}
.tg-search:focus-within {
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.tg-search__icon { width: 17px; height: 17px; }
.tg-search__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  color: var(--text);
  font-size: 14px;
}
.tg-search__input::placeholder { color: var(--text-tertiary); }

/* ---- add contact row ---- */
.tg-add {
  display: none;
  gap: 8px;
  padding: 10px 14px 12px;
  flex: none;
  border-bottom: 1px solid var(--border);
}
.tg-add.open { display: flex; animation: slideDown .22s var(--ease); }
.tg-add__input { flex: 1; min-width: 0; height: 44px; }
.tg-add .tg-btn { height: 44px; padding: 0 18px; }

/* ---- chat list ---- */
.tg-chatlist { flex: 1; overflow-y: auto; padding: 6px 10px 14px; }
.tg-chatlist .tg-empty { height: 100%; min-height: 320px; }

.tg-chat-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  margin-bottom: 2px;
  transition: background .16s var(--ease), transform .16s var(--ease);
}
.tg-chat-item:hover { background: var(--hover); }
.tg-chat-item:active { transform: scale(.99); }
.tg-chat-item.active {
  background: var(--grad-accent);
  box-shadow: 0 6px 20px var(--accent-glow);
}
.tg-chat-item.active .tg-chat-item__name,
.tg-chat-item.active .tg-chat-item__preview,
.tg-chat-item.active .tg-chat-item__time { color: rgba(255, 255, 255, .95); }
.tg-chat-item.active .tg-chat-item__read { color: rgba(255, 255, 255, .9); }
.tg-chat-item.active .avatar { box-shadow: 0 0 0 2px rgba(255,255,255,.4); }

.tg-chat-item__body { flex: 1; min-width: 0; }
.tg-chat-item__row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tg-chat-item__name {
  font-weight: 600; font-size: 15px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tg-chat-item__time { font-size: 11.5px; color: var(--text-tertiary); flex: none; font-weight: 500; }
.tg-chat-item__preview {
  font-size: 13.5px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px;
}
.tg-unread {
  min-width: 21px; height: 21px; padding: 0 7px; border-radius: 11px;
  background: var(--online); color: #fff; font-size: 11.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  box-shadow: 0 3px 8px rgba(34, 197, 94, .35);
}
.tg-chat-item__read { color: var(--text-tertiary); display: inline-flex; flex: none; }

/* ---- avatars ---- */
.avatar {
  width: 54px; height: 54px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 600; font-size: 18px; color: #fff; user-select: none; letter-spacing: .02em;
  position: relative;
  box-shadow: inset 0 -2px 6px rgba(0,0,0,.16), 0 2px 6px rgba(16,24,40,.08);
}
.avatar::after {
  content: "";
  position: absolute; inset: 0; border-radius: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,.22), transparent 52%);
  pointer-events: none;
}
.avatar--lg { width: 54px; height: 54px; font-size: 18px; }
.avatar--md { width: 42px; height: 42px; font-size: 15px; }
.avatar--xs { width: 34px; height: 34px; font-size: 13px; }

/* ---- menu dropdown ---- */
.tg-menu { position: relative; flex: none; }
.tg-menu .dropdown-menu {
  min-width: 300px;
  left: 0;
  top: calc(100% + 10px);
  padding-top: 0;
}
.tg-menu__panel {
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), var(--ring);
  overflow: hidden;
  animation: popIn .18s var(--spring);
}
.tg-menu__profile {
  display: flex; align-items: center; gap: 13px;
  padding: 8px 10px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.tg-menu__identity { min-width: 0; }
.tg-menu__alias { font-weight: 700; font-size: 15px; color: var(--text); }
.tg-menu__pub {
  font-size: 12px; color: var(--text-tertiary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tg-menu__conn { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-secondary); margin-top: 5px; }

.tg-menu__item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: none;
  text-align: left;
  transition: background .15s var(--ease);
}
.tg-menu__item:hover { background: var(--hover); }
.tg-menu__item--danger { color: var(--danger); }
.tg-menu__item--danger:hover { background: rgba(239, 68, 68, .1); }
.tg-menu__icon { width: 20px; height: 20px; }
.tg-menu__divider { border: none; border-top: 1px solid var(--border); margin: 6px 0; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-tertiary); }
.status-dot.online { background: var(--online); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); animation: pulse 2.2s infinite; }
.status-dot.offline { background: var(--warning); }

/* ---- conversation ---- */
.tg-chat__header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  z-index: 6;
}
.tg-chat__identity {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  background: transparent; border: none; text-align: left; padding: 0; cursor: pointer;
}
.tg-chat__title { flex: 1; min-width: 0; }
.tg-chat__name { font-weight: 700; font-size: 16px; color: var(--text); display: flex; align-items: center; }
.tg-chat__status {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-secondary); margin-top: 2px;
}
.tg-chat__status .icon { width: 12px; height: 12px; }
.tg-chat__lock { width: 14px; height: 14px; color: var(--text-tertiary); margin-left: 6px; }
.back-btn { display: none; }

/* glass header + composer when blur is available */
@supports ((-webkit-backdrop-filter: blur(18px)) or (backdrop-filter: blur(18px))) {
  .tg-chat__header, .tg-composer {
    background: var(--surface-glass);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
  }
}

/* ---- messages ---- */
.tg-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 22px;
  background-color: var(--bg);
  background-image: var(--chat-bg-pattern), var(--chat-bg);
}

.tg-day { text-align: center; margin: 16px 0 10px; }
.tg-day span {
  display: inline-block;
  padding: 4px 14px;
  border-radius: var(--radius-full);
  background: var(--panel);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  box-shadow: var(--shadow-sm), var(--ring);
}

.tg-msg-group { display: flex; gap: 9px; margin: 5px 0; }
.tg-msg-group.theirs { justify-content: flex-start; }
.tg-msg-group.mine { justify-content: flex-end; }
.tg-msg-group .avatar--xs { margin-top: auto; }

.tg-msg-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  max-width: 76%;
  min-width: 0;
}
.tg-msg-group.mine .tg-msg-stack { align-items: flex-end; }

.tg-bubble {
  display: inline-flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  padding: 9px 13px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.48;
  box-shadow: var(--shadow-sm);
  word-break: break-word;
}
.tg-bubble.mine { background: var(--bubble-out); color: #fff; box-shadow: 0 4px 16px var(--accent-glow); }
.tg-bubble.theirs { background: var(--bubble-in); color: var(--text); border: 1px solid var(--bubble-in-border); }
.tg-bubble__text { white-space: pre-wrap; word-break: break-word; min-width: 0; }
.tg-bubble__meta {
  flex: none;
  font-size: 10.5px;
  line-height: 1;
  color: var(--mine-meta);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-bottom: 1px;
  white-space: nowrap;
}
.tg-bubble.theirs .tg-bubble__meta { color: var(--theirs-meta); }
.tg-bubble__meta .icon { width: 14px; height: 14px; }

/* tails */
.tg-bubble.first.mine { border-top-right-radius: 5px; }
.tg-bubble.first.theirs { border-top-left-radius: 5px; }
.tg-bubble.last.mine { border-bottom-right-radius: 5px; }
.tg-bubble.last.theirs { border-bottom-left-radius: 5px; }

.tg-bubble--pending { opacity: .7; }
.tg-bubble--failed {
  background: transparent;
  box-shadow: none;
  border: 1px dashed var(--border-strong);
  color: var(--text-secondary);
  font-size: 13px;
  align-items: center;
  gap: 6px;
}
.tg-bubble--failed .icon { width: 14px; height: 14px; }

/* ---- composer ---- */
.tg-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex: none;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  z-index: 6;
}
.tg-composer .tg-icon-btn { width: 46px; height: 46px; }
.tg-composer__box {
  flex: 1;
  display: flex;
  align-items: flex-end;
  min-width: 0;
  background: var(--input-bg);
  border: 1px solid transparent;
  border-radius: 23px;
  padding: 3px 6px 3px 16px;
  transition: border .18s var(--ease), background .18s var(--ease), box-shadow .2s var(--ease);
}
.tg-composer__box:focus-within {
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.tg-composer__input {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  outline: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding: 11px 0;
  max-height: 140px;
}
.tg-composer__input::placeholder { color: var(--text-tertiary); }

.tg-send {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex: none;
  background: var(--grad-accent);
  color: #fff;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px var(--accent-glow);
  transition: transform .15s var(--spring), filter .18s var(--ease), box-shadow .2s var(--ease);
}
.tg-send:hover:not(:disabled) { filter: brightness(1.07); box-shadow: 0 8px 22px var(--accent-glow); }
.tg-send:active:not(:disabled) { transform: scale(.9); }
.tg-send:disabled { opacity: .45; cursor: default; box-shadow: none; }
.tg-send .icon { width: 22px; height: 22px; }

/* ---- scroll-to-bottom ---- */
.tg-scrollbtn {
  position: absolute;
  bottom: 88px;
  right: 22px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  z-index: 5;
  transition: color .15s var(--ease), transform .15s var(--spring), box-shadow .18s var(--ease);
}
.tg-scrollbtn.visible { display: inline-flex; animation: popIn .2s var(--spring); }
.tg-scrollbtn:hover { color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.tg-scrollbtn .icon { width: 20px; height: 20px; }

/* ---- empty states ---- */
.tg-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  color: var(--text-secondary);
  padding: 40px 24px;
}
.tg-empty--chat { flex: 1; }
.tg-empty__icon {
  width: 88px; height: 88px; border-radius: 28px;
  display: grid; place-items: center;
  background: var(--grad-accent-soft);
  color: var(--accent);
  margin-bottom: 8px;
  box-shadow: inset 0 0 0 1px var(--accent-soft);
}
.tg-empty__icon .icon { width: 40px; height: 40px; }
.tg-empty h3 { font-size: 17px; font-weight: 700; color: var(--text); }
.tg-empty p { max-width: 360px; font-size: 14px; line-height: 1.55; }
.tg-empty__icon--float { animation: float 3.5s ease-in-out infinite; }

/* ---- emoji picker ---- */
.tg-emoji {
  position: absolute;
  left: 18px; right: 18px; bottom: 86px;
  max-height: 260px; overflow-y: auto;
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), var(--ring);
  padding: 8px;
  z-index: 30;
}
.tg-emoji.open { display: grid; animation: popIn .18s var(--spring); }
.tg-emoji__btn {
  width: 100%; height: 44px; font-size: 24px; line-height: 1;
  display: grid; place-items: center; border-radius: var(--radius-sm);
  background: transparent; border: none; cursor: pointer;
  transition: background .1s var(--ease), transform .08s var(--spring);
}
.tg-emoji__btn:hover { background: var(--hover); transform: scale(1.1); }
.tg-icon-btn.active { background: var(--accent-soft); color: var(--accent); }

/* ---- context menu ---- */
.tg-ctx {
  position: fixed; z-index: 120; min-width: 200px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg), var(--ring); padding: 6px;
  opacity: 0; transform: scale(.94); transform-origin: top left;
  transition: opacity .14s var(--ease), transform .14s var(--spring);
}
.tg-ctx.open { opacity: 1; transform: scale(1); }
.tg-ctx__item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px;
  color: var(--text); background: transparent; border: none; text-align: left;
  font-weight: 500;
  transition: background .12s var(--ease);
}
.tg-ctx__item:hover { background: var(--hover); }
.tg-ctx__item--danger { color: var(--danger); }
.tg-ctx__item--danger:hover { background: rgba(239, 68, 68, .1); }
.tg-ctx__icon { width: 18px; height: 18px; }

/* ---- sheets (modals) ---- */
.tg-sheet {
  position: fixed; inset: 0; z-index: 110;
  background: rgba(8, 11, 20, .5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 20px;
  opacity: 0; transition: opacity .2s var(--ease);
}
.tg-sheet.open { opacity: 1; }
.tg-sheet__card {
  width: 100%; max-width: 384px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  padding: 24px; transform: translateY(12px) scale(.97);
  transition: transform .22s var(--spring);
  max-height: 86vh; overflow-y: auto;
}
.tg-sheet.open .tg-sheet__card { transform: none; }
.tg-sheet__title { font-size: 18px; font-weight: 700; color: var(--text); }
.tg-sheet__body { font-size: 14px; color: var(--text-secondary); margin-top: 7px; line-height: 1.55; }
.tg-sheet__actions { display: flex; gap: 10px; margin-top: 22px; }
.tg-sheet__actions .tg-btn { flex: 1; height: 46px; }

/* ---- contact info ---- */
.tg-contact { display: flex; flex-direction: column; gap: 18px; }
.tg-contact__head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
.tg-contact__head .avatar { width: 88px; height: 88px; font-size: 30px; }
.tg-contact__field {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--input-bg); border-radius: var(--radius-md); padding: 14px;
}
.tg-contact__label { font-size: 11.5px; font-weight: 700; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: .06em; }
.tg-contact__pub {
  font-family: var(--font-mono);
  font-size: 12.5px; color: var(--text); word-break: break-all; line-height: 1.55;
}
.tg-contact__copy { width: 100%; height: 46px; }
.tg-contact__note {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 13px; color: var(--text-secondary);
}
.tg-contact__note .icon { width: 14px; height: 14px; color: var(--online); }

/* ---- misc ---- */
.tg-unread-sep { text-align: center; margin: 16px 0 10px; }
.tg-unread-sep span {
  display: inline-block; padding: 4px 14px; border-radius: var(--radius-full);
  background: var(--accent-soft); color: var(--accent); font-size: 11.5px; font-weight: 700;
}

.tg-menu__copy {
  display: inline-flex; align-items: center; gap: 5px; padding: 0;
  color: var(--text-tertiary); font-size: 12px; background: transparent; border: none; cursor: pointer;
  font-family: var(--font-mono);
}
.tg-menu__copy:hover { color: var(--accent); }
.tg-menu__copy .icon { width: 12px; height: 12px; }

/* ============================ toasts ============================ */
.toast-root {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 100;
  align-items: center; pointer-events: none;
}
.toast {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg), var(--ring); padding: 13px 20px;
  font-size: 13.5px; font-weight: 600; animation: toastIn .3s var(--spring); max-width: 90vw;
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}
.toast.error { border-color: rgba(239, 68, 68, .4); color: var(--danger); }

/* ============================ animations ============================ */
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(.86); } to { opacity: 1; transform: scale(1); } }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px) scale(.95); } to { opacity: 1; transform: none; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 3px rgba(34,197,94,.18); } 50% { box-shadow: 0 0 0 7px rgba(34,197,94,.04); } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@keyframes drift {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-4vmax, 3vmax) scale(1.12); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* ============================ responsive ============================ */
@media (max-width: 900px) {
  .tg-sidebar { flex-basis: 36%; }
  .tg-msg-stack { max-width: 82%; }
}

@media (max-width: 800px) {
  .tg-sidebar { flex: 1 1 auto; width: 100%; max-width: none; min-width: 0; border-right: none; }
  .tg-chat {
    position: fixed;
    inset: 0;
    z-index: 10;
    transform: translateX(100%);
    transition: transform .28s var(--ease);
  }
  .tg.chat-open .tg-chat { transform: translateX(0); }
  .back-btn { display: inline-flex; }
  .tg-msg-stack { max-width: 86%; }
  .tg-messages { padding: 14px 14px 18px; }
  .tg-composer { padding: 10px 12px 14px; }
  .tg-sheet { align-items: flex-end; padding: 0; }
  .tg-sheet__card { max-width: none; border-radius: 24px 24px 0 0; padding-bottom: 30px; }
  .tg-emoji { left: 12px; right: 12px; bottom: 80px; }
}
