/* Чат поддержки: секция на главной и выезжающая панель в креаторе.
   Обе оболочки используют одну разметку .support-chat, поэтому цвета заданы
   локальными токенами — блок одинаково ложится и на тёмный фон лендинга, и на
   светлую тему. */

/* Собственный display у блоков чата перебивает атрибут hidden — возвращаем
   ему силу, иначе гостевая заглушка висит поверх работающей формы. */
.support-chat [hidden],
.support-dock [hidden],
.support-panel [hidden] {
  display: none !important;
}

.support-chat .visually-hidden {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip-path: inset(50%);
  white-space: nowrap;
}

.support-chat {
  --support-surface: rgba(6, 13, 26, 0.66);
  --support-surface-strong: rgba(9, 17, 32, 0.92);
  --support-border: rgba(93, 135, 210, 0.3);
  --support-ink: #f2f7ff;
  --support-muted: #9fb0c9;
  --support-bubble-in: rgba(18, 30, 52, 0.94);
  --support-bubble-in-ink: #e8f1ff;
  --support-bubble-out: linear-gradient(135deg, #1874d9, #0d5fc7);
  --support-bubble-out-ink: #ffffff;

  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--support-border);
  border-radius: 20px;
  background: var(--support-surface);
  backdrop-filter: blur(14px);
  box-shadow: 0 26px 70px rgba(2, 8, 20, 0.42);
  color: var(--support-ink);
  font-family: inherit;
}

html[data-theme="light"] .support-chat {
  --support-surface: rgba(255, 253, 252, 0.94);
  --support-surface-strong: #fffdfc;
  --support-border: rgba(34, 35, 38, 0.14);
  --support-ink: #222326;
  --support-muted: #68635f;
  --support-bubble-in: #f0ece5;
  --support-bubble-in-ink: #222326;
  box-shadow: 0 22px 54px rgba(67, 52, 44, 0.14);
}

/* ------------------------------- шапка чата ------------------------------- */

.support-chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px 18px;
  border-bottom: 1px solid var(--support-border);
  background: var(--support-surface-strong);
}

.support-chat-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  overflow: hidden;
  border-radius: 50%;
  background: rgba(24, 116, 217, 0.16);
}

.support-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.support-chat-heading {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.support-chat-name {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.support-chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--support-muted);
  font-size: 13px;
  line-height: 1.3;
}

.support-chat-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #46d18b;
  box-shadow: 0 0 0 3px rgba(70, 209, 139, 0.18);
}

/* ------------------------------- лента реплик ----------------------------- */

.support-chat-log {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  padding: 18px;
  scrollbar-width: thin;
}

.support-chat-log::-webkit-scrollbar {
  width: 8px;
}

.support-chat-log::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--support-border);
  background-clip: content-box;
}

.support-chat-day {
  align-self: center;
  margin: 6px 0;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--support-bubble-in);
  color: var(--support-muted);
  font-size: 12px;
}

.support-chat-message {
  display: flex;
  max-width: 100%;
}

.support-chat-message[data-sender="user"] {
  justify-content: flex-end;
}

.support-chat-bubble {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(86%, 460px);
  padding: 10px 14px 8px;
  border-radius: 16px;
  background: var(--support-bubble-in);
  color: var(--support-bubble-in-ink);
  animation: support-bubble-in 260ms cubic-bezier(0.22, 0.8, 0.28, 1) both;
}

.support-chat-message[data-sender="user"] .support-chat-bubble {
  border-bottom-right-radius: 6px;
  background: var(--support-bubble-out);
  color: var(--support-bubble-out-ink);
}

.support-chat-message[data-sender="admin"] .support-chat-bubble {
  border-bottom-left-radius: 6px;
}

.support-chat-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.support-chat-time {
  align-self: flex-end;
  font-size: 11px;
  line-height: 1;
  opacity: 0.68;
}

/* Начисление монет — не реплика, а событие: карточка во всю ширину ленты,
   чтобы её нельзя было пролистать мимо. */
.support-chat-message[data-kind="grant"] {
  justify-content: center;
}

.support-chat-message[data-kind="grant"] .support-chat-bubble {
  width: 100%;
  max-width: 100%;
  align-items: stretch;
  padding: 14px 16px 10px;
  border: 1px solid rgba(243, 188, 98, 0.46);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(243, 188, 98, 0.22), rgba(243, 188, 98, 0.07));
  color: var(--support-ink);
  box-shadow: 0 10px 30px rgba(243, 188, 98, 0.1);
}

html[data-theme="light"] .support-chat-message[data-kind="grant"] .support-chat-bubble {
  border-color: rgba(203, 143, 43, 0.38);
  background: linear-gradient(135deg, rgba(243, 188, 98, 0.3), rgba(243, 188, 98, 0.14));
  box-shadow: none;
}

.support-chat-grant {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0 12px;
}

.support-chat-grant img {
  grid-row: span 2;
  width: 34px;
  height: 34px;
}

.support-chat-grant-amount {
  color: #f3bc62;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.15;
}

html[data-theme="light"] .support-chat-grant-amount {
  color: #b57a17;
}

.support-chat-grant-note {
  font-size: 12px;
  line-height: 1.3;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.66;
}

.support-chat-message[data-kind="grant"] .support-chat-text {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(243, 188, 98, 0.24);
  font-size: 14px;
}

.support-chat-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.support-chat-images img {
  display: block;
  width: 104px;
  height: 104px;
  border-radius: 10px;
  object-fit: cover;
}

.support-chat-empty,
.support-chat-hint {
  margin: auto 0;
  color: var(--support-muted);
  font-size: 14px;
  line-height: 1.55;
  text-align: center;
}

.support-chat-empty p {
  margin: 0 auto;
  max-width: 320px;
}

/* --------------------------------- ввод ---------------------------------- */

/* На узких экранах каждый уровень обязан уметь сжиматься: у grid- и
   flex-элементов min-width по умолчанию равен min-content, из-за чего строка
   ввода держала свою ширину и выталкивала кнопку отправки за край. */
.support-chat-form {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--support-border);
  background: var(--support-surface-strong);
}

.support-chat-form > * {
  min-width: 0;
}

.support-chat-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
}

.support-chat-input {
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  max-height: 140px;
  min-height: 44px;
  padding: 11px 14px;
  border: 1px solid var(--support-border);
  border-radius: 14px;
  background: var(--support-bubble-in);
  color: var(--support-ink);
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
}

.support-chat-input::placeholder {
  color: var(--support-muted);
}

.support-chat-input:focus {
  outline: none;
  border-color: rgba(24, 116, 217, 0.6);
  box-shadow: 0 0 0 3px rgba(24, 116, 217, 0.16);
}

.support-chat-attach,
.support-chat-send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 1px solid var(--support-border);
  border-radius: 14px;
  background: var(--support-bubble-in);
  color: var(--support-ink);
  cursor: pointer;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease;
}

.support-chat-attach svg,
.support-chat-send svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.support-chat-attach:hover,
.support-chat-send:hover {
  border-color: rgba(24, 116, 217, 0.5);
}

.support-chat-send {
  border-color: transparent;
  background: var(--support-bubble-out);
  color: #ffffff;
}

.support-chat-send:hover {
  transform: translateY(-1px);
}

.support-chat-send:disabled,
.support-chat-attach:has(input:disabled) {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.support-chat-attach input {
  display: none;
}

.support-chat-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.support-chat-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: var(--support-bubble-in);
  color: var(--support-muted);
  font-size: 12px;
}

.support-chat-file > span {
  overflow: hidden;
  max-width: 160px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.support-chat-file button {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.support-chat-error {
  margin: 0;
  color: #ff9d9d;
  font-size: 13px;
  line-height: 1.4;
}

html[data-theme="light"] .support-chat-error {
  color: #c33b3b;
}

.support-chat-legal {
  margin: 0;
  color: var(--support-muted);
  font-size: 11px;
  line-height: 1.4;
}

.support-chat-legal a {
  color: inherit;
  text-decoration: underline;
}

/* ----------------------------- гостевое состояние ------------------------- */

.support-chat-guest {
  display: grid;
  gap: 12px;
  justify-items: center;
  padding: 16px 18px 20px;
  border-top: 1px solid var(--support-border);
  background: var(--support-surface-strong);
  text-align: center;
}

.support-chat-guest p {
  margin: 0;
  color: var(--support-muted);
  font-size: 14px;
  line-height: 1.5;
}

.support-chat-guest button {
  padding: 12px 26px;
  border: 0;
  border-radius: 12px;
  background: var(--support-bubble-out);
  color: #ffffff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease;
}

.support-chat-guest button:hover {
  transform: translateY(-1px);
}

/* --------------------------- вариант «секция» ----------------------------- */

.support-chat[data-support-variant="section"] {
  height: min(520px, 72vh);
}

/* --------------------------- язычок и панель ------------------------------ */

/* Язычок-вкладка: узкая колонка «иконка + подпись», прижатая к правому краю.
   В покое — стеклянная, при непрочитанных — фирменный синий. */
.support-tab {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 62;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 9px 18px;
  border: 1px solid rgba(120, 165, 235, 0.22);
  border-right: 0;
  border-radius: 14px 0 0 14px;
  background: linear-gradient(180deg, rgba(16, 29, 51, 0.92), rgba(9, 17, 31, 0.92));
  backdrop-filter: blur(12px);
  color: #cfe2fb;
  font: inherit;
  cursor: pointer;
  transform: translateY(-50%);
  box-shadow:
    -1px 0 0 rgba(255, 255, 255, 0.04) inset,
    -16px 0 40px rgba(2, 8, 20, 0.4);
  transition:
    transform 220ms cubic-bezier(0.22, 0.8, 0.28, 1),
    border-color 200ms ease,
    color 200ms ease,
    box-shadow 200ms ease,
    opacity 200ms ease;
}

.support-tab:hover {
  color: #ffffff;
  border-color: rgba(120, 165, 235, 0.42);
  transform: translateY(-50%) translateX(-3px);
  box-shadow: -20px 0 46px rgba(2, 8, 20, 0.5);
}

.support-tab:focus-visible {
  outline: 2px solid var(--blue, #1874d9);
  outline-offset: 3px;
}

.support-tab:active {
  transform: translateY(-50%) translateX(-1px);
}

html[data-theme="light"] .support-tab {
  border-color: rgba(34, 35, 38, 0.1);
  background: linear-gradient(180deg, rgba(255, 253, 252, 0.96), rgba(244, 241, 236, 0.96));
  color: #4a5568;
  box-shadow: -14px 0 34px rgba(67, 52, 44, 0.14);
}

html[data-theme="light"] .support-tab:hover {
  color: #1874d9;
  border-color: rgba(24, 116, 217, 0.28);
}

.support-tab-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: rgba(90, 150, 240, 0.14);
  transition: background-color 200ms ease;
}

.support-tab:hover .support-tab-icon {
  background: rgba(90, 150, 240, 0.22);
}

html[data-theme="light"] .support-tab-icon {
  background: rgba(24, 116, 217, 0.1);
}

.support-tab svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.support-tab-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.85;
}

/* Кружок непрочитанных садится на иконку и обводится цветом подложки —
   так он читается как значок мессенджера, а не как ошибка вёрстки. */
.support-tab-badge {
  position: absolute;
  top: -7px;
  right: -8px;
  display: grid;
  place-items: center;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border: 2px solid #0b1424;
  border-radius: 999px;
  background: #e02f4c;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  animation: support-badge-pop 320ms cubic-bezier(0.22, 0.8, 0.28, 1) both;
}

html[data-theme="light"] .support-tab-badge {
  border-color: #fbf9f6;
}

.support-tab.has-unread {
  border-color: rgba(24, 116, 217, 0.5);
  background: linear-gradient(180deg, #1874d9, #0d5fc7);
  color: #ffffff;
  box-shadow: -18px 0 44px rgba(13, 95, 199, 0.34);
}

.support-tab.has-unread .support-tab-icon {
  background: rgba(255, 255, 255, 0.18);
}

.support-tab.has-unread .support-tab-label {
  opacity: 1;
}

html[data-theme="light"] .support-tab.has-unread {
  color: #ffffff;
}

html[data-theme="light"] .support-tab.has-unread .support-tab-badge {
  border-color: #1874d9;
}

/* Пока панель открыта, язычок уезжает за край — он бы дублировал заголовок. */
body.has-support-panel .support-tab {
  opacity: 0;
  transform: translateY(-50%) translateX(100%);
  pointer-events: none;
}

.support-panel {
  position: fixed;
  inset: 0;
  z-index: 82;
}

.support-panel-scrim {
  position: absolute;
  inset: 0;
  background: rgba(2, 7, 16, 0.52);
  opacity: 0;
  transition: opacity 240ms ease;
}

.support-panel.is-open .support-panel-scrim {
  opacity: 1;
}

.support-panel-body {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  width: min(420px, 100vw);
  height: 100%;
  border-left: 1px solid var(--support-border, rgba(93, 135, 210, 0.3));
  background: rgba(4, 10, 20, 0.96);
  box-shadow: -30px 0 70px rgba(2, 8, 20, 0.5);
  transform: translateX(100%);
  transition: transform 260ms cubic-bezier(0.22, 0.8, 0.28, 1);
}

html[data-theme="light"] .support-panel-body {
  background: #f7f4ef;
  box-shadow: -24px 0 60px rgba(67, 52, 44, 0.2);
}

.support-panel.is-open .support-panel-body {
  transform: translateX(0);
}

.support-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
}

.support-panel-title {
  margin: 0;
  color: #f2f7ff;
  font-size: 17px;
  font-weight: 800;
}

html[data-theme="light"] .support-panel-title {
  color: #222326;
}

.support-panel-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(93, 135, 210, 0.3);
  border-radius: 10px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.support-panel-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.support-panel .support-chat {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 12px 12px;
  box-shadow: none;
}

/* Язычок и панель — десктопная история: на телефоне чат живёт в секции
   главной, а холст креатора и без того тесный. */
@media (max-width: 900px), (hover: none) and (pointer: coarse) {
  .support-dock {
    display: none;
  }
}

/* ------------------------------- мобильная ------------------------------- */

@media (max-width: 780px) {
  .support-chat[data-support-variant="section"] {
    height: min(460px, 66vh);
    border-radius: 16px;
  }

  .support-chat-head {
    padding: 12px 14px;
  }

  .support-chat-log {
    padding: 14px;
  }

  .support-chat-form {
    padding: 10px 12px 12px;
  }

  .support-chat-images img {
    width: 88px;
    height: 88px;
  }
}

@keyframes support-bubble-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes support-badge-pop {
  from {
    transform: scale(0.4);
  }

  to {
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .support-chat-bubble,
  .support-tab-badge {
    animation: none;
  }

  .support-panel-body,
  .support-panel-scrim {
    transition: none;
  }
}
