/* Telegram-like site chat — light / dark */
:root,
[data-theme="light"] {
  --tg-bg: #e6ebee;
  --tg-sidebar: #ffffff;
  --tg-sidebar-border: #dfe5eb;
  --tg-chat-bg: #8bb9d4;
  --tg-chat-pattern: rgba(255,255,255,.08);
  --tg-header: #ffffff;
  --tg-text: #0f1419;
  --tg-muted: #707579;
  --tg-mine: #effdde;
  --tg-theirs: #ffffff;
  --tg-accent: #2AABEE;
  --tg-accent-2: #229ED9;
  --tg-danger: #e53935;
  --tg-input: #ffffff;
  --tg-hover: #f0f2f5;
  --tg-active: #e7f3fb;
  --tg-shadow: 0 1px 2px rgba(16, 35, 47, .12);
  --tg-bubble-shadow: 0 1px 1px rgba(0,0,0,.08);
  --tg-unread: #2AABEE;
  --tg-composer-border: #dfe5eb;
}

[data-theme="dark"] {
  --tg-bg: #0e1621;
  --tg-sidebar: #17212b;
  --tg-sidebar-border: #0e1621;
  --tg-chat-bg: #0e1621;
  --tg-chat-pattern: rgba(255,255,255,.03);
  --tg-header: #17212b;
  --tg-text: #f5f5f5;
  --tg-muted: #7f8b95;
  --tg-mine: #2b5278;
  --tg-theirs: #182533;
  --tg-accent: #2AABEE;
  --tg-accent-2: #64B5EF;
  --tg-danger: #ef5350;
  --tg-input: #242f3d;
  --tg-hover: #202b36;
  --tg-active: #2b5278;
  --tg-shadow: none;
  --tg-bubble-shadow: none;
  --tg-unread: #2AABEE;
  --tg-composer-border: #0e1621;
}

* { box-sizing: border-box; }

html, body.tg-body {
  height: 100%;
  margin: 0;
  font-family: "Segoe UI", Tahoma, "IRANSans", sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
}

.tg-shell {
  display: flex;
  height: 100vh;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  background: var(--tg-sidebar);
  overflow: hidden;
  box-shadow: var(--tg-shadow);
}

.tg-shell.public {
  flex-direction: column;
  max-width: 780px;
}

.tg-sidebar {
  width: 360px;
  min-width: 280px;
  background: var(--tg-sidebar);
  border-left: 1px solid var(--tg-sidebar-border);
  display: flex;
  flex-direction: column;
}

.tg-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .85rem 1rem;
  background: var(--tg-header);
  border-bottom: 1px solid var(--tg-sidebar-border);
}

.tg-sidebar-head strong { font-size: .95rem; }
.tg-sidebar-head .sub { font-size: .75rem; color: var(--tg-muted); }

.tg-logo-sm {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--tg-hover);
}

.tg-icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--tg-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
}
.tg-icon-btn:hover { background: var(--tg-hover); color: var(--tg-text); }

.tg-conv-list { overflow: auto; flex: 1; }

.tg-conv-item {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: right;
  padding: .8rem 1rem;
  cursor: pointer;
  color: var(--tg-text);
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: .75rem;
  align-items: center;
  border-bottom: 1px solid transparent;
}
.tg-conv-item:hover { background: var(--tg-hover); }
.tg-conv-item.active { background: var(--tg-active); }

.tg-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #64B5EF, #2AABEE);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.tg-conv-title {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  align-items: center;
}
.tg-conv-title strong { font-size: .92rem; }
.tg-conv-title .time { font-size: .72rem; color: var(--tg-muted); }
.tg-conv-preview {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  margin-top: .15rem;
  font-size: .8rem;
  color: var(--tg-muted);
}
.tg-conv-preview .preview {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.tg-unread {
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--tg-unread);
  color: #fff;
  font-size: .68rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.tg-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--tg-chat-bg);
  position: relative;
}

.tg-main::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 20%, var(--tg-chat-pattern) 0 2px, transparent 3px),
    radial-gradient(circle at 80% 40%, var(--tg-chat-pattern) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 40% 70%, var(--tg-chat-pattern) 0 2px, transparent 3px);
  background-size: 48px 48px;
  pointer-events: none;
  opacity: .9;
}

.tg-public-brand {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1rem;
  background: var(--tg-header);
  border-bottom: 1px solid var(--tg-sidebar-border);
}
.tg-public-brand img {
  max-height: 44px;
  max-width: 160px;
  object-fit: contain;
}

.tg-empty {
  position: relative;
  z-index: 1;
  margin: auto;
  text-align: center;
  color: #fff;
  background: rgba(0,0,0,.18);
  padding: 1.25rem 1.5rem;
  border-radius: 16px;
  backdrop-filter: blur(4px);
}
.tg-empty i { font-size: 2.4rem; display: block; margin-bottom: .5rem; }
[data-theme="light"] .tg-empty { color: #16324a; background: rgba(255,255,255,.55); }

.tg-pane {
  position: relative;
  z-index: 1;
  display: none;
  flex-direction: column;
  height: 100%;
}
.tg-pane.active { display: flex; }
.tg-shell.public .tg-pane { display: flex; min-height: 0; flex: 1; }

.tg-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .7rem 1rem;
  background: var(--tg-header);
  border-bottom: 1px solid var(--tg-sidebar-border);
}
.tg-pane-head .name { font-weight: 700; font-size: .98rem; }
.tg-pane-head .meta { font-size: .78rem; color: var(--tg-muted); margin-top: 2px; }
.tg-pane-head .ip { font-family: ui-monospace, Consolas, monospace; direction: ltr; display: inline-block; }

.tg-messages {
  flex: 1;
  overflow: auto;
  padding: 1rem 1.1rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.tg-bubble-row {
  display: flex;
  width: 100%;
}
.tg-bubble-row.mine { justify-content: flex-start; }
.tg-bubble-row.theirs { justify-content: flex-end; }

.tg-bubble {
  max-width: min(78%, 460px);
  padding: .45rem .65rem .3rem;
  border-radius: 12px;
  box-shadow: var(--tg-bubble-shadow);
  line-height: 1.45;
  word-break: break-word;
  position: relative;
  font-size: .95rem;
}
.tg-bubble-row.mine .tg-bubble {
  background: var(--tg-mine);
  border-bottom-right-radius: 4px;
}
.tg-bubble-row.theirs .tg-bubble {
  background: var(--tg-theirs);
  border-bottom-left-radius: 4px;
}

.tg-reply-ref {
  display: block;
  font-size: .75rem;
  color: var(--tg-accent-2);
  border-right: 3px solid var(--tg-accent);
  padding: .15rem .45rem;
  margin-bottom: .3rem;
  background: rgba(42,171,238,.08);
  border-radius: 4px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tg-bubble-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .45rem;
  margin-top: .15rem;
}
.tg-bubble-foot .time {
  font-size: .68rem;
  color: var(--tg-muted);
}
.tg-reply-btn {
  border: 0;
  background: transparent;
  color: var(--tg-accent);
  font-size: .7rem;
  padding: 0;
  cursor: pointer;
  opacity: .85;
}
.tg-reply-btn:hover { opacity: 1; text-decoration: underline; }

.tg-bubble img.sticker {
  width: 88px;
  height: 88px;
  display: block;
}

.tg-offline-banner {
  position: relative;
  z-index: 2;
  background: #fff3cd;
  color: #856404;
  text-align: center;
  padding: .55rem .85rem;
  font-size: .85rem;
  border-bottom: 1px solid rgba(133, 100, 4, .15);
}
[data-theme="dark"] .tg-offline-banner {
  background: #3d3420;
  color: #ffd666;
  border-bottom-color: rgba(255, 214, 102, .15);
}

.tg-typing {
  display: none;
  align-items: center;
  gap: .45rem;
  padding: 0 1.1rem .35rem;
  color: var(--tg-muted);
  font-size: .8rem;
  position: relative;
  z-index: 1;
}
.tg-typing.show { display: flex; }
.tg-typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--tg-muted);
  display: inline-block;
  animation: tgDot 1.2s infinite ease-in-out;
}
.tg-typing-dots span:nth-child(2) { animation-delay: .15s; }
.tg-typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes tgDot {
  0%, 80%, 100% { transform: translateY(0); opacity: .4; }
  40% { transform: translateY(-3px); opacity: 1; }
}

.tg-reply-bar,
.tg-stickers {
  position: relative;
  z-index: 2;
  background: var(--tg-header);
  border-top: 1px solid var(--tg-composer-border);
  padding: .55rem .85rem;
}
.tg-reply-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.tg-reply-bar.show { display: flex; }
.tg-reply-bar .label {
  font-size: .8rem;
  color: var(--tg-accent);
  border-right: 3px solid var(--tg-accent);
  padding-right: .5rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tg-stickers {
  display: none;
  flex-wrap: wrap;
  gap: .45rem;
}
.tg-stickers.show { display: flex; }
.tg-sticker-btn {
  width: 52px;
  height: 52px;
  border: 1px solid var(--tg-sidebar-border);
  border-radius: 12px;
  background: var(--tg-input);
  padding: .2rem;
  cursor: pointer;
}
.tg-sticker-btn img { width: 100%; height: 100%; }

.tg-composer {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .55rem .75rem .7rem;
  background: var(--tg-header);
  border-top: 1px solid var(--tg-composer-border);
}
.tg-composer input {
  flex: 1;
  border: 0;
  outline: none;
  background: var(--tg-input);
  color: var(--tg-text);
  border-radius: 22px;
  padding: .65rem 1rem;
  font-size: .95rem;
}
.tg-composer .tg-send {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--tg-accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.tg-composer .tg-send:hover { background: var(--tg-accent-2); }

.tg-name-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(8, 16, 24, .45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.tg-name-modal.show { display: flex; }
.tg-name-card {
  width: min(380px, 100%);
  background: var(--tg-sidebar);
  color: var(--tg-text);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.tg-name-card h3 { margin: 0 0 .35rem; font-size: 1.05rem; }
.tg-name-card p { margin: 0 0 1rem; color: var(--tg-muted); font-size: .85rem; }
.tg-name-card input {
  width: 100%;
  border: 1px solid var(--tg-sidebar-border);
  background: var(--tg-input);
  color: var(--tg-text);
  border-radius: 10px;
  padding: .7rem .85rem;
  margin-bottom: .85rem;
}
.tg-name-card button {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: .7rem;
  background: var(--tg-accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.tg-close-btn {
  border: 0;
  background: transparent;
  color: var(--tg-danger);
  font-size: .8rem;
  cursor: pointer;
  padding: .35rem .55rem;
  border-radius: 8px;
}
.tg-close-btn:hover { background: rgba(229,57,53,.1); }

.floating-site-chat-widget {
  position: fixed;
  z-index: 997;
}
.floating-site-chat-widget.position-bottom-right { bottom: 20px; right: 20px; }
.floating-site-chat-widget.position-bottom-left { bottom: 20px; left: 20px; }
.floating-site-chat-widget.position-top-right { top: 20px; right: 20px; }
.floating-site-chat-widget.position-top-left { top: 20px; left: 20px; }

@media (max-width: 991px) {
  .floating-site-chat-widget.position-bottom-right,
  .floating-site-chat-widget.position-bottom-left { bottom: 80px; }
}

.floating-site-chat-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
  cursor: pointer;
  text-decoration: none;
  transition: transform .2s ease;
}
.floating-site-chat-btn:hover { transform: scale(1.08); color: #fff; }

@media (max-width: 900px) {
  .tg-shell.admin { flex-direction: column; }
  .tg-sidebar {
    width: 100%;
    max-height: 38vh;
    border-left: 0;
    border-bottom: 1px solid var(--tg-sidebar-border);
  }
}
