/* Гостевой чат поддержки на публичном сайте.
   Самодостаточный CSS: не зависит от Bootstrap/утилит, использует токены сайта
   (--ink, --ivory, --card, --line, --terra, --r) с фолбэками. */

.sn-gc {
  --gc-ink: var(--ink, #211B15);
  --gc-soft: var(--ink-soft, #5A5148);
  --gc-card: var(--card, #FFFFFF);
  --gc-ivory: var(--ivory-2, #F4EDE1);
  --gc-line: var(--line, #E7DECF);
  --gc-accent: var(--terra, #B24A32);
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 900;
  font-family: 'Inter', system-ui, sans-serif;
}

.sn-gc-hide { display: none !important; }

/* --- кнопка --- */
.sn-gc-fab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 999px;
  background: var(--gc-accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 14px 30px -12px rgba(178, 74, 50, .75);
  transition: transform .2s ease, background .2s ease;
}
.sn-gc-fab:hover { background: #9d3f2b; transform: translateY(-2px); }
.sn-gc-fab:focus-visible { outline: 3px solid rgba(178, 74, 50, .35); outline-offset: 3px; }
.sn-gc-fab svg { width: 26px; height: 26px; }

.sn-gc-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 21px;
  height: 21px;
  padding: 0 6px;
  border-radius: 999px;
  background: #2F7D4F;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 21px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--gc-card);
}

/* --- панель --- */
.sn-gc-panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  display: flex;
  flex-direction: column;
  width: 360px;
  max-height: min(560px, calc(100vh - 130px));
  overflow: hidden;
  background: var(--gc-card);
  border: 1px solid var(--gc-line);
  border-radius: var(--r, 18px);
  box-shadow: 0 24px 60px -28px rgba(46, 33, 20, .45);
  animation: snGcIn .18s ease-out;
}
@keyframes snGcIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .sn-gc-panel { animation: none; } }

.sn-gc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px;
  background: var(--gc-ivory);
  border-bottom: 1px solid var(--gc-line);
}
.sn-gc-head-txt { display: flex; flex-direction: column; gap: 2px; }
.sn-gc-head strong { font-size: 15px; color: var(--gc-ink); }
.sn-gc-sub { font-size: 12.5px; color: var(--gc-soft); }
.sn-gc-x {
  border: none;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  color: var(--gc-soft);
  cursor: pointer;
  padding: 0 4px;
}
.sn-gc-x:hover { color: var(--gc-ink); }

/* --- стартовый экран --- */
.sn-gc-start { padding: 18px 16px 16px; overflow-y: auto; }
.sn-gc-lead { font-size: 14.5px; color: var(--gc-ink); margin-bottom: 12px; }
.sn-gc-row { display: flex; flex-direction: column; gap: 5px; }
.sn-gc-label { font-size: 12.5px; font-weight: 600; color: var(--gc-soft); }
.sn-gc-start input[type=text] {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  font-size: 14.5px;
  color: var(--gc-ink);
  background: #fff;
  border: 1px solid var(--gc-line);
  border-radius: 12px;
}
.sn-gc-start input[type=text]:focus {
  outline: none;
  border-color: var(--gc-accent);
  box-shadow: 0 0 0 3px rgba(178, 74, 50, .12);
}
.sn-gc-hp { position: absolute !important; left: -9999px !important; opacity: 0 !important; height: 0 !important; }

.sn-gc-btn {
  width: 100%;
  margin-top: 12px;
  padding: 12px 18px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--gc-accent);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background .2s ease;
}
.sn-gc-btn:hover { background: #9d3f2b; }
.sn-gc-btn[disabled] { opacity: .6; cursor: default; }

.sn-gc-err { margin-top: 9px; font-size: 13px; color: #B0402A; }

.sn-gc-chips-label {
  margin: 20px 0 9px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gc-soft);
}
.sn-gc-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.sn-gc-chip {
  padding: 8px 13px;
  font: inherit;
  font-size: 13px;
  color: var(--gc-ink);
  background: var(--gc-ivory);
  border: 1px solid var(--gc-line);
  border-radius: 999px;
  cursor: pointer;
  text-align: left;
  transition: background .18s ease, border-color .18s ease;
}
.sn-gc-chip:hover { background: #fff; border-color: var(--gc-accent); }
.sn-gc-chip.active { background: var(--gc-accent); border-color: var(--gc-accent); color: #fff; }

/* --- переписка --- */
.sn-gc-thread-wrap { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.sn-gc-thread { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.sn-gc-msgs {
  flex: 1;
  min-height: 220px;
  padding: 14px 14px 4px;
  overflow-y: auto;
  background: var(--gc-ivory);
}
.sn-gc-empty { font-size: 13.5px; color: var(--gc-soft); text-align: center; padding: 26px 12px; }

.sn-gc-msg {
  max-width: 86%;
  margin-bottom: 10px;
  padding: 9px 12px;
  background: #fff;
  border: 1px solid var(--gc-line);
  border-radius: 14px 14px 14px 4px;
}
.sn-gc-msg.me {
  margin-left: auto;
  background: var(--gc-accent);
  border-color: var(--gc-accent);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
}
.sn-gc-msg-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 3px;
  font-size: 11.5px;
  color: var(--gc-soft);
}
.sn-gc-msg.me .sn-gc-msg-meta { color: rgba(255, 255, 255, .82); }
.sn-gc-msg-text { font-size: 14px; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere; }
.sn-gc-msg-img img { border-radius: 10px; margin-top: 6px; max-height: 190px; width: auto; }
.sn-gc-msg-file { display: inline-flex; gap: 6px; margin-top: 6px; font-size: 13px; text-decoration: underline; }

.sn-gc-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px;
  background: var(--gc-card);
  border-top: 1px solid var(--gc-line);
}
.sn-gc-form textarea {
  flex: 1;
  resize: none;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  color: var(--gc-ink);
  border: 1px solid var(--gc-line);
  border-radius: 12px;
}
.sn-gc-form textarea:focus {
  outline: none;
  border-color: var(--gc-accent);
  box-shadow: 0 0 0 3px rgba(178, 74, 50, .12);
}
.sn-gc-send {
  padding: 10px 15px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--gc-accent);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.sn-gc-send:hover { background: #9d3f2b; }
.sn-gc-send[disabled] { opacity: .6; cursor: default; }

/* --- галочки «отправлено / прочитано» (у своих сообщений) ---
   Один чек = сообщение сохранено на сервере (по факту — отправлено).
   Второй чек проявляется, когда собеседник открыл чат: consumers.py шлёт
   messages_read по вебсокету, JS помечает элемент data-read="1". */
/* Мета — flex со space-between; без этого правила третий элемент (галочки)
   растащил бы имя, время и галочки по всей ширине. Auto-margin у времени
   собирает «время + галочки» в правый край, имя остаётся слева. */
.sn-gc-msg-meta > span:not(.sn-ticks) { margin-left: auto; }
.sn-gc-msg-meta > strong { min-width: 0; overflow-wrap: anywhere; }

.sn-ticks { display: inline-flex; flex: none; margin-left: 4px; vertical-align: middle; opacity: .68; }
.sn-tick-2 { margin-left: -7px; }
.sn-ticks[data-read="0"] .sn-tick-2 { display: none; }
.sn-ticks[data-read="1"] { opacity: 1; }

/* --- «Администрация печатает…» --- */
.sn-gc-typing {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 10px;
  padding: 8px 12px;
  max-width: 86%;
  font-size: 12.5px;
  color: var(--gc-soft);
  background: #fff;
  border: 1px solid var(--gc-line);
  border-radius: 14px 14px 14px 4px;
}
.sn-typing-dots { display: inline-flex; gap: 3px; }
.sn-typing-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--gc-soft);
  animation: snTypingBounce 1.2s infinite ease-in-out;
}
.sn-typing-dots span:nth-child(2) { animation-delay: .15s; }
.sn-typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes snTypingBounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-3px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sn-typing-dots span { animation: none; } }

/* --- мобильные --- */
@media (max-width: 520px) {
  .sn-gc { right: 14px; bottom: 14px; }
  .sn-gc-panel {
    position: fixed;
    inset: 10px 10px 84px;
    width: auto;
    max-height: none;
  }
}
