/* Buyer chat — витрина + CRM (не наследие art-decoupage / глобальных button) */
.buyer-chat {
  --bc-pink: #ff4285;
  --bc-pink-dark: #d11d84;
  --bc-pink-soft: #fff0f6;
  --bc-ink: #1f1f1f;
  --bc-muted: #6b6b6b;
  --bc-line: #f0d6e4;
  --bc-panel: #ffffff;
  --bc-shadow: 0 18px 44px rgba(209, 29, 132, 0.16);

  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 50;
  width: min(22.5rem, calc(100vw - 2rem));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.65rem;
  pointer-events: none;
  color: var(--bc-ink);
  font-family: inherit;
  box-sizing: border-box;
}

.buyer-chat *,
.buyer-chat *::before,
.buyer-chat *::after {
  box-sizing: border-box;
}

.buyer-chat[hidden] {
  display: none !important;
}

.buyer-chat > * {
  pointer-events: auto;
}

.buyer-chat.is-expanded {
  width: min(32rem, calc(100vw - 1.5rem));
}

/* Сброс глобальных button/.btn из app.css (оранжевый accent) */
.buyer-chat button,
.crm.crm-shell .buyer-chat button,
.buyer-chat .btn {
  display: inline-grid;
  margin: 0 !important;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  box-shadow: none;
  text-decoration: none;
  font: inherit;
  font-weight: inherit;
  border-radius: 0;
  line-height: 1;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.buyer-chat-toggle {
  position: relative;
  display: inline-flex !important;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.15rem !important;
  border-radius: 999px !important;
  background: linear-gradient(135deg, var(--bc-pink), var(--bc-pink-dark)) !important;
  color: #fff !important;
  font-weight: 600 !important;
  box-shadow: 0 10px 26px rgba(209, 29, 132, 0.28) !important;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.buyer-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(209, 29, 132, 0.34) !important;
}

.buyer-chat-toggle-badge {
  position: absolute;
  top: -0.35rem;
  right: -0.2rem;
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.32rem;
  border-radius: 999px;
  background: #fff;
  color: var(--bc-pink-dark);
  border: 2px solid var(--bc-pink);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  display: inline-grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(209, 29, 132, 0.28);
}

/* display:inline-grid иначе перебивает [hidden] — пустой кружок не должен светиться */
.buyer-chat-toggle-badge[hidden] {
  display: none !important;
}

.buyer-chat-panel {
  width: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  background: var(--bc-panel);
  border: 1px solid var(--bc-line);
  border-radius: 18px;
  box-shadow: var(--bc-shadow);
  overflow: hidden;
  transform-origin: bottom left;
}

.buyer-chat-panel[hidden] {
  display: none !important;
}

.buyer-chat.is-open .buyer-chat-panel,
.buyer-chat.is-visible .buyer-chat-panel {
  display: grid;
  animation: buyer-chat-pop 0.45s cubic-bezier(0.2, 0.9, 0.25, 1.12);
}

@keyframes buyer-chat-pop {
  0% { opacity: 0; transform: translateY(1rem) scale(0.94); }
  70% { opacity: 1; transform: translateY(-0.12rem) scale(1.01); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.buyer-chat-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, #ff6a9e 0%, var(--bc-pink) 48%, var(--bc-pink-dark) 100%);
  color: #fff;
}

.buyer-chat-head-text {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.buyer-chat-head-text strong {
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.25;
}

.buyer-chat-head-text span {
  font-size: 0.76rem;
  opacity: 0.95;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.buyer-chat-head-text span::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #7dffb0;
  box-shadow: 0 0 0 2px rgba(125, 255, 176, 0.35);
  flex-shrink: 0;
}

.buyer-chat-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.buyer-chat-close,
.buyer-chat-expand {
  width: 2.1rem !important;
  height: 2.1rem !important;
  border-radius: 50% !important;
  background: rgba(255, 255, 255, 0.18) !important;
  color: #fff !important;
  font-size: 1.15rem;
  place-items: center;
  transition: background 0.15s ease;
}

.buyer-chat-close:hover,
.buyer-chat-expand:hover {
  background: rgba(255, 255, 255, 0.3) !important;
}

.buyer-chat.is-expanded .buyer-chat-expand {
  background: rgba(255, 255, 255, 0.3) !important;
}

.buyer-chat-log {
  max-height: 16.5rem;
  min-height: 8.5rem;
  overflow: auto;
  padding: 0.95rem 0.9rem;
  display: grid;
  gap: 0.75rem;
  background: linear-gradient(180deg, var(--bc-pink-soft) 0%, #fff 100%);
}

.buyer-chat.is-expanded .buyer-chat-log {
  max-height: min(28rem, calc(100vh - 14rem));
  min-height: 14rem;
}

.buyer-chat-msg {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  max-width: 100%;
}

.buyer-chat-msg.is-mine {
  justify-content: flex-end;
}

.buyer-chat-msg-avatar {
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
  border: 1px solid var(--bc-line);
  background: var(--bc-pink-soft);
  display: inline-grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--bc-pink-dark);
}

.buyer-chat-msg-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.buyer-chat-msg-stack {
  display: grid;
  gap: 0.3rem;
  max-width: min(100%, 16.5rem);
}

.buyer-chat.is-expanded .buyer-chat-msg-stack {
  max-width: min(100%, 22rem);
}

.buyer-chat-msg-name {
  font-size: 0.72rem;
  color: var(--bc-muted);
  padding: 0 0.25rem;
}

.buyer-chat-msg.is-mine .buyer-chat-msg-name {
  text-align: right;
}

.buyer-chat-msg-body {
  display: inline-block;
  padding: 0.65rem 0.8rem;
  border-radius: 1rem;
  font-size: 0.9rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fff;
  border: 1px solid var(--bc-line);
  border-bottom-left-radius: 0.3rem;
  box-shadow: 0 2px 8px rgba(209, 29, 132, 0.05);
}

.buyer-chat-msg.is-mine .buyer-chat-msg-body {
  background: linear-gradient(135deg, #ffe4f0, #ffd0e4);
  border: 1px solid #f0b6d0;
  border-bottom-right-radius: 0.3rem;
  border-bottom-left-radius: 1rem;
}

.buyer-chat-msg-quote {
  display: block;
  margin: 0 0 0.35rem;
  padding: 0.35rem 0.5rem;
  border-left: 3px solid var(--bc-pink);
  background: rgba(255, 66, 133, 0.08);
  border-radius: 0.35rem;
  font-size: 0.78rem;
  color: var(--bc-muted);
}

.buyer-chat-msg-actions {
  display: flex;
  gap: 0.35rem;
  padding: 0 0.15rem;
}

.buyer-chat-msg-actions button {
  font-size: 0.72rem !important;
  color: var(--bc-pink-dark) !important;
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.buyer-chat-typing {
  padding: 0.2rem 1rem 0.4rem;
  font-size: 0.76rem;
  color: var(--bc-muted);
  min-height: 1.1rem;
}

.buyer-chat-typing[hidden],
.buyer-chat-reply[hidden],
.buyer-chat-preview[hidden] {
  display: none !important;
}

.buyer-chat-reply {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  align-items: center;
  padding: 0.5rem 0.85rem;
  border-top: 1px solid var(--bc-line);
  background: var(--bc-pink-soft);
}

.buyer-chat-reply-body {
  min-width: 0;
  display: grid;
  gap: 0.1rem;
}

.buyer-chat-reply-body strong {
  font-size: 0.78rem;
  color: var(--bc-pink-dark);
}

.buyer-chat-reply-body span {
  font-size: 0.78rem;
  color: var(--bc-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.buyer-chat-reply-cancel {
  width: 1.75rem !important;
  height: 1.75rem !important;
  place-items: center;
  font-size: 1.1rem;
  color: var(--bc-muted) !important;
  border-radius: 50% !important;
}

.buyer-chat-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 0.5rem;
  padding: 0.75rem 0.85rem 0.85rem;
  border-top: 1px solid var(--bc-line);
  background: #fff;
  min-width: 0;
  width: 100%;
}

.buyer-chat-attach {
  width: 2.55rem;
  height: 2.55rem;
  margin: 0 0 0.15rem;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  color: var(--bc-pink-dark);
  cursor: pointer;
  background: var(--bc-pink-soft);
  position: relative;
  overflow: hidden;
}

.buyer-chat-file {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  font-size: 0;
}

.buyer-chat-attach[hidden] {
  display: none !important;
}

.buyer-chat-input {
  width: 100%;
  min-width: 0;
  max-width: none !important;
  border: 1px solid #f0c4d8;
  border-radius: 1rem !important;
  padding: 0.55rem 0.85rem;
  font: inherit;
  line-height: 1.35;
  background: #fffafc;
  resize: none;
  overflow-y: auto;
  min-height: calc(1.35em * 3 + 1.1rem);
  max-height: calc(1.35em * 8 + 1.1rem);
  field-sizing: content;
  color: var(--bc-ink);
}

.buyer-chat-input:focus {
  outline: 2px solid rgba(255, 66, 133, 0.28);
  outline-offset: 1px;
  border-color: #f0a0c0;
  background: #fff;
}

.buyer-chat-form button[type="submit"] {
  width: 2.55rem !important;
  height: 2.55rem !important;
  margin: 0 0 0.15rem !important;
  border-radius: 50% !important;
  background: linear-gradient(135deg, var(--bc-pink), var(--bc-pink-dark)) !important;
  color: #fff !important;
  place-items: center;
  box-shadow: 0 4px 12px rgba(209, 29, 132, 0.22) !important;
}

.buyer-chat-form button[type="submit"]:hover {
  filter: brightness(0.97);
}

.buyer-chat-form button[type="submit"]:disabled {
  opacity: 0.55;
  cursor: wait;
}

.buyer-chat-preview {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  align-items: center;
  padding: 0 0.85rem 0.75rem;
  background: #fff;
}

.buyer-chat-preview img,
.buyer-chat-preview video {
  max-height: 4.5rem;
  max-width: 100%;
  border-radius: 0.5rem;
  object-fit: cover;
  background: #1c1b19;
}

.buyer-chat-preview img[hidden],
.buyer-chat-preview video[hidden] {
  display: none !important;
}

.buyer-chat-preview button {
  width: 1.75rem !important;
  height: 1.75rem !important;
  place-items: center;
  font-size: 1.2rem;
  color: var(--bc-muted) !important;
  border-radius: 50% !important;
}

.buyer-chat-msg-img,
.buyer-chat-msg-video {
  display: block;
  max-width: 100%;
  width: 100%;
  height: auto;
  min-height: 4rem;
  background: var(--bc-pink-soft);
  border-radius: 0.65rem;
  margin-top: 0.35rem;
}

.buyer-chat-msg-video {
  max-height: 14rem;
  background: #1c1b19;
}

.buyer-chat-announce-link {
  display: inline-block;
  margin-top: 0.45rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--bc-pink-dark);
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.buyer-chat-msg-reply {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  padding: 0.12rem 0.1rem !important;
  font-size: 0.68rem !important;
  font-weight: 500;
  color: var(--bc-muted) !important;
}

.buyer-chat-msg-reply svg {
  flex: 0 0 auto;
  opacity: 0.85;
}

.buyer-chat-msg-reply:hover {
  color: var(--bc-pink-dark) !important;
}

.buyer-chat-msg-text a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.12em;
  word-break: break-word;
}

.buyer-chat-msg.is-mine .buyer-chat-msg-text a {
  color: var(--bc-pink-dark);
}

.buyer-chat-msg-edited {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.68rem;
  color: var(--bc-muted);
  font-weight: 500;
}

.buyer-chat-msg-icon {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 1.35rem !important;
  height: 1.35rem !important;
  border-radius: 999px !important;
  color: var(--bc-muted) !important;
}

.buyer-chat-msg-icon:hover {
  color: var(--bc-pink-dark) !important;
  background: rgba(255, 66, 133, 0.1) !important;
}

.buyer-chat-msg-icon.is-danger:hover {
  color: #b42318 !important;
  background: rgba(180, 35, 24, 0.08) !important;
}

.buyer-chat-msg-edit-input {
  width: 100%;
  max-width: none !important;
  border: 1px solid rgba(28, 27, 25, 0.18);
  border-radius: 0.45rem !important;
  padding: 0.35rem 0.5rem;
  font: inherit;
  font-size: 0.9rem;
  background: #fff;
}

.buyer-chat-msg-edit-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.buyer-chat-msg-edit-actions button {
  border-radius: 0.4rem !important;
  padding: 0.3rem 0.6rem !important;
  font-size: 0.72rem !important;
  font-weight: 600 !important;
}

.buyer-chat-msg-edit-save {
  background: var(--bc-pink) !important;
  color: #fff !important;
}

.buyer-chat-msg-edit-cancel {
  background: rgba(28, 27, 25, 0.08) !important;
  color: #1c1b19 !important;
}

.buyer-chat-modal {
  border: 0;
  border-radius: 0.9rem;
  padding: 0;
  max-width: min(92vw, 20rem);
  box-shadow: 0 18px 48px rgba(28, 27, 25, 0.22);
}

.buyer-chat-modal::backdrop {
  background: rgba(28, 27, 25, 0.42);
}

.buyer-chat-modal-card {
  margin: 0;
  padding: 1.15rem 1.2rem 1.05rem;
  display: grid;
  gap: 0.95rem;
}

.buyer-chat-modal-card p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.4;
  color: #1c1b19;
}

.buyer-chat-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.buyer-chat-modal-cancel,
.buyer-chat-modal-confirm {
  border-radius: 0.5rem !important;
  padding: 0.5rem 0.85rem !important;
  font-size: 0.85rem !important;
  font-weight: 600 !important;
}

.buyer-chat-modal-cancel {
  background: rgba(28, 27, 25, 0.08) !important;
  color: #1c1b19 !important;
}

.buyer-chat-modal-confirm {
  background: #b42318 !important;
  color: #fff !important;
}

@media (max-width: 640px) {
  .buyer-chat {
    left: 0.65rem;
    bottom: 0.65rem;
    width: min(20.5rem, calc(100vw - 1.3rem));
  }

  .buyer-chat.is-expanded {
    width: calc(100vw - 1.3rem);
  }
}
