﻿#tgChatBtn {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 999999;
  width: 62px;
  height: 62px;
  border: none;
  border-radius: 20px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #f7fbff;
  background: linear-gradient(145deg, #2c7cff 0%, #5a57ff 55%, #35c4ff 100%);
  box-shadow: 0 18px 36px rgba(10, 26, 60, 0.36), 0 3px 12px rgba(66, 95, 255, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

#tgChatBtn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 20px 40px rgba(10, 26, 60, 0.42), 0 6px 15px rgba(66, 95, 255, 0.48);
}

#tgChatBtn:active {
  transform: translateY(0) scale(0.97);
}

#tgChatBtn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(108, 146, 255, 0.4), 0 20px 40px rgba(10, 26, 60, 0.42);
}

#tgChatBtn .tg-chat-btn-ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(255, 255, 255, 0.34);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

#tgChatBtn .tg-chat-btn-icon {
  position: relative;
  z-index: 2;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#tgChatBtn .tg-chat-btn-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

#tgChatBtn .tg-chat-btn-label {
  position: absolute;
  left: 72px;
  white-space: nowrap;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(6, 12, 30, 0.86);
  color: #f4f7ff;
  font: 600 12px/1 "Segoe UI", Arial, sans-serif;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.24);
  opacity: 0;
  transform: translateX(-6px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

#tgChatBtn:hover .tg-chat-btn-label,
#tgChatBtn:focus-visible .tg-chat-btn-label {
  opacity: 1;
  transform: translateX(0);
}

#tgChatBox {
  position: fixed;
  right: 22px;
  bottom: 96px;
  z-index: 999999;
  width: min(390px, calc(100vw - 28px));
  height: min(560px, calc(100vh - 126px));
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  border: 1px solid rgba(130, 149, 255, 0.28);
  background: linear-gradient(180deg, rgba(8, 16, 34, 0.96) 0%, rgba(7, 13, 30, 0.93) 100%);
  color: #ecf3ff;
  box-shadow: 0 28px 70px rgba(7, 12, 30, 0.56), 0 2px 20px rgba(25, 56, 180, 0.22);
  backdrop-filter: blur(16px) saturate(140%);
  overflow: hidden;
  opacity: 0;
  transform: translateY(18px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.26s cubic-bezier(0.2, 0.85, 0.25, 1);
}

#tgChatBox[hidden] {
  display: none !important;
}

#tgChatBox.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

#tgChatHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 13px;
  border-bottom: 1px solid rgba(122, 144, 255, 0.22);
  background: linear-gradient(160deg, rgba(34, 60, 141, 0.44), rgba(20, 33, 70, 0.2));
}

.tg-chat-title-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tg-chat-title {
  font: 700 15px/1.2 "Segoe UI", Arial, sans-serif;
  letter-spacing: 0.01em;
  color: #f6f9ff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.24);
}

#tgChatStatus {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 600 11px/1 "Segoe UI", Arial, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9eb4dd;
}

#tgChatStatus::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #7d8ca6;
  box-shadow: 0 0 0 3px rgba(120, 140, 168, 0.18);
}

#tgChatStatus[data-state="ok"] {
  color: #95f3c0;
}

#tgChatStatus[data-state="ok"]::before {
  background: #2ecc71;
  box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.2);
}

#tgChatStatus[data-state="error"] {
  color: #ff9ca7;
}

#tgChatStatus[data-state="error"]::before {
  background: #f0526d;
  box-shadow: 0 0 0 3px rgba(240, 82, 109, 0.2);
}

#tgChatClose {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(176, 194, 255, 0.22);
  background: rgba(16, 27, 57, 0.42);
  color: #d7e4ff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

#tgChatClose:hover {
  background: rgba(24, 40, 82, 0.72);
  border-color: rgba(176, 194, 255, 0.35);
  transform: translateY(-1px);
}

#tgChatClose:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(108, 146, 255, 0.35);
}

#tgChatClose svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
}

#tgChatIdentity {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(122, 144, 255, 0.16);
  background: rgba(18, 28, 57, 0.4);
}

#tgChatName {
  width: 100%;
  min-width: 0;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(114, 136, 219, 0.34);
  background: rgba(7, 14, 31, 0.58);
  color: #e9f1ff;
  padding: 0 11px;
  font: 500 13px/1 "Segoe UI", Arial, sans-serif;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

#tgChatName::placeholder {
  color: #94a8cf;
}

#tgChatName:focus {
  border-color: #6f95ff;
  box-shadow: 0 0 0 3px rgba(84, 120, 255, 0.2);
}

#tgChatNameSave {
  height: 36px;
  min-width: 68px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid rgba(140, 162, 240, 0.38);
  background: linear-gradient(180deg, rgba(44, 70, 150, 0.9), rgba(29, 52, 122, 0.9));
  color: #edf3ff;
  font: 600 12px/1 "Segoe UI", Arial, sans-serif;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, filter 0.18s ease;
}

#tgChatNameSave:hover {
  border-color: rgba(178, 196, 255, 0.55);
  transform: translateY(-1px);
  filter: brightness(1.06);
}

#tgChatNameSave:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(108, 146, 255, 0.35);
}

#tgChatMessages {
  flex: 1 1 auto;
  min-height: 0;
  padding: 14px 12px 10px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at 10% -20%, rgba(108, 133, 255, 0.18) 0%, rgba(108, 133, 255, 0) 40%),
    radial-gradient(circle at 110% 10%, rgba(55, 195, 255, 0.14) 0%, rgba(55, 195, 255, 0) 38%),
    linear-gradient(180deg, rgba(12, 20, 43, 0.2), rgba(7, 13, 31, 0.12));
}

#tgChatMessages::-webkit-scrollbar {
  width: 8px;
}

#tgChatMessages::-webkit-scrollbar-track {
  background: transparent;
}

#tgChatMessages::-webkit-scrollbar-thumb {
  background: rgba(133, 154, 211, 0.45);
  border-radius: 999px;
}

.tgChatRow {
  display: flex;
}

.tgChatRow.user {
  justify-content: flex-end;
}

.tgChatBubbleWrap {
  max-width: 84%;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tgChatBubble {
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.45;
  font: 500 13px/1.45 "Segoe UI", Arial, sans-serif;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 8px 18px rgba(8, 14, 32, 0.26);
}

.tgChatRow.admin .tgChatBubble {
  background: linear-gradient(180deg, rgba(25, 39, 78, 0.95), rgba(18, 30, 62, 0.95));
  border: 1px solid rgba(103, 125, 214, 0.26);
  color: #edf3ff;
  border-bottom-left-radius: 7px;
}

.tgChatRow.user .tgChatBubble {
  background: linear-gradient(180deg, #3c72ff, #5d5bff);
  border: 1px solid rgba(169, 189, 255, 0.45);
  color: #ffffff;
  border-bottom-right-radius: 7px;
}

.tgChatMeta {
  color: #8fa4ce;
  font: 500 10px/1 "Segoe UI", Arial, sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0 3px;
}

.tgChatRow.user .tgChatMeta {
  text-align: right;
  color: #c8d4ff;
}

#tgChatFooter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(122, 144, 255, 0.19);
  background: linear-gradient(180deg, rgba(17, 27, 55, 0.72), rgba(11, 21, 45, 0.86));
}

#tgChatInput {
  flex: 1;
  min-width: 0;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(107, 130, 210, 0.34);
  background: rgba(7, 14, 31, 0.58);
  color: #ecf3ff;
  padding: 0 13px;
  font: 500 13px/1 "Segoe UI", Arial, sans-serif;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

#tgChatInput::placeholder {
  color: #93a7cd;
}

#tgChatInput:focus {
  border-color: #6f95ff;
  box-shadow: 0 0 0 3px rgba(84, 120, 255, 0.2);
}

#tgChatSend {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 12px;
  border: 1px solid rgba(170, 190, 255, 0.45);
  background: linear-gradient(180deg, #4e7eff, #4d5fff);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}

#tgChatSend svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#tgChatSend:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(77, 106, 255, 0.38);
}

#tgChatSend:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(108, 146, 255, 0.35), 0 8px 18px rgba(77, 106, 255, 0.38);
}

#tgChatSend:disabled {
  cursor: wait;
}

#tgChatSend.is-busy {
  filter: saturate(0.7);
  opacity: 0.76;
}

body.theme-light #tgChatBtn {
  color: #f6fbff;
  background: linear-gradient(145deg, #1a79ff 0%, #4958ff 52%, #35b5ff 100%);
  box-shadow: 0 18px 36px rgba(25, 72, 176, 0.3), 0 3px 12px rgba(84, 120, 230, 0.35);
}

body.theme-light #tgChatBtn .tg-chat-btn-label {
  background: rgba(255, 255, 255, 0.95);
  color: #1f3772;
  box-shadow: 0 8px 20px rgba(79, 109, 186, 0.22);
}

body.theme-light #tgChatBox {
  border-color: rgba(82, 116, 216, 0.24);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(245, 250, 255, 0.96));
  color: #1a2a44;
  box-shadow: 0 24px 60px rgba(75, 103, 175, 0.24), 0 2px 18px rgba(112, 142, 214, 0.18);
}

body.theme-light #tgChatHeader {
  border-bottom-color: rgba(129, 154, 217, 0.34);
  background: linear-gradient(180deg, rgba(238, 245, 255, 0.98), rgba(228, 239, 255, 0.86));
}

body.theme-light .tg-chat-title {
  color: #1c2f57;
  text-shadow: none;
}

body.theme-light #tgChatStatus {
  color: #57739d;
}

body.theme-light #tgChatClose {
  background: rgba(255, 255, 255, 0.84);
  border-color: rgba(130, 154, 224, 0.4);
  color: #39548a;
}

body.theme-light #tgChatClose:hover {
  background: rgba(247, 251, 255, 0.98);
  border-color: rgba(110, 136, 210, 0.52);
}

body.theme-light #tgChatIdentity {
  border-bottom-color: rgba(143, 167, 222, 0.3);
  background: rgba(239, 246, 255, 0.75);
}

body.theme-light #tgChatName {
  border-color: #c7d8f3;
  background: #ffffff;
  color: #1a2a44;
}

body.theme-light #tgChatName::placeholder {
  color: #7990b8;
}

body.theme-light #tgChatNameSave {
  border-color: #95b3ff;
  background: linear-gradient(180deg, #5f8dff, #4b74ea);
  color: #ffffff;
}

body.theme-light #tgChatMessages {
  background:
    radial-gradient(circle at 8% -20%, rgba(99, 136, 255, 0.14) 0%, rgba(99, 136, 255, 0) 40%),
    radial-gradient(circle at 112% 8%, rgba(37, 186, 250, 0.13) 0%, rgba(37, 186, 250, 0) 38%),
    linear-gradient(180deg, rgba(247, 251, 255, 0.86), rgba(240, 247, 255, 0.75));
}

body.theme-light .tgChatRow.admin .tgChatBubble {
  background: #eef4ff;
  border-color: #c8dbff;
  color: #1e3358;
  box-shadow: 0 8px 18px rgba(120, 148, 206, 0.2);
}

body.theme-light .tgChatMeta {
  color: #6f84a9;
}

body.theme-light .tgChatRow.user .tgChatMeta {
  color: #5875b0;
}

body.theme-light #tgChatFooter {
  border-top-color: rgba(143, 167, 222, 0.34);
  background: rgba(241, 247, 255, 0.95);
}

body.theme-light #tgChatInput {
  border-color: #c6d8f7;
  background: #ffffff;
  color: #1c2f56;
}

body.theme-light #tgChatInput::placeholder {
  color: #7f97be;
}

body.theme-light #tgChatSend {
  border-color: #4f7aff;
  box-shadow: 0 6px 14px rgba(79, 122, 255, 0.22);
}

@media (max-width: 640px) {
  #tgChatBtn {
    right: 14px;
    bottom: 14px;
    width: 56px;
    height: 56px;
    border-radius: 17px;
  }

  #tgChatBtn .tg-chat-btn-label {
    display: none;
  }

  #tgChatBox {
    right: 10px;
    left: 10px;
    bottom: 82px;
    width: auto;
    height: min(72vh, 540px);
  }

  #tgChatHeader {
    padding: 12px 11px;
  }

  #tgChatIdentity,
  #tgChatMessages,
  #tgChatFooter {
    padding-left: 10px;
    padding-right: 10px;
  }
}
