/* ── CONTENT ── */
.content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #ffffff;
}

.content-top {
  height: 52px;
  padding: 0 14px;
  border-bottom: 1px solid #e9e9e7;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-title-main {
  font-size: 15px;
  font-weight: 700;
  color: #37352f;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.content-actions { display: flex; gap: 4px; }

/* ── ITEM CARD ── */
.item-card {
  display: none;
  padding: 8px 14px;
  border-bottom: 1px solid #e9e9e7;
  background: #f7f6f3;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.item-card.visible { display: flex; }

.item-card-img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e9e9e7;
  flex-shrink: 0;
}

.item-card-avatar {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #ffffff;
  text-transform: uppercase;
}

.item-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.item-card-title {
  font-size: 13px;
  font-weight: 600;
  color: #37352f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-card-price {
  font-size: 15px;
  font-weight: 700;
  color: #2383e2;
}

.item-card-link {
  font-size: 12px;
  color: #2383e2;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.item-card-link:hover { text-decoration: underline; }

/* ── CHAT PANEL ── */
.chat-panel {
  padding: 8px 14px;
  border-bottom: 1px solid #e9e9e7;
  background: #fafaf9;
  display: none;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.chat-panel.visible { display: flex; }

.status-pills { display: flex; gap: 6px; flex-wrap: wrap; }

.status-pill {
  padding: 3px 12px;
  font-size: 12px;
  border-radius: 20px;
  border: 1px solid #e9e9e7;
  background: #ffffff;
  color: #37352f;
  cursor: pointer;
  font-family: inherit;
}
.status-pill:hover { background: #f1f1ef; }
.status-pill[data-status="new"].active         { background: #f1f1ef; color: #37352f; border-color: #9b9a97; }
.status-pill[data-status="in_progress"].active { background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
.status-pill[data-status="ordered"].active     { background: #fef9c3; color: #92400e; border-color: #fde047; }
.status-pill[data-status="done"].active        { background: #dcfce7; color: #15803d; border-color: #86efac; }

.note-row { display: flex; gap: 8px; align-items: flex-end; }

.note-row textarea {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #e9e9e7;
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  resize: none;
  height: 46px;
  color: #37352f;
  background: #ffffff;
  outline: none;
}
.note-row textarea:focus { border-color: #2383e2; }

.save-btn {
  padding: 0 14px;
  font-size: 12px;
  border-radius: 6px;
  border: 0;
  background: #2383e2;
  color: #ffffff;
  cursor: pointer;
  flex-shrink: 0;
  height: 30px;
  font-family: inherit;
}
.save-btn:hover { background: #1a6fc4; }
.save-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── MESSAGES ── */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #ffffff;
}

.message {
  max-width: 68%;
  display: flex;
  flex-direction: column;
}
.message.in  { align-self: flex-start; }
.message.out { align-self: flex-end; }

.message-bubble {
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.in .message-bubble {
  background: #f3f3f1;
  border: 1px solid #e4e4e2;
  border-radius: 2px 12px 12px 12px;
  color: #37352f;
}
.message.out .message-bubble {
  background: #2383e2;
  border-radius: 12px 2px 12px 12px;
  color: #ffffff;
}

.message-time {
  font-size: 10px;
  color: #9b9a97;
  margin-top: 3px;
  padding: 0 2px;
}
.message.out .message-time { text-align: right; }

/* ── MESSAGE GROUPING ── */
.message.group-first,
.message.group-mid {
  margin-bottom: -4px;
}

/* Скругления для входящих в группе */
.message.in.group-first .message-bubble { border-radius: 2px 12px 12px 4px; }
.message.in.group-mid   .message-bubble { border-radius: 4px 12px 12px 4px; }
.message.in.group-last  .message-bubble { border-radius: 4px 12px 12px 12px; }

/* Скругления для исходящих в группе */
.message.out.group-first .message-bubble { border-radius: 12px 2px 4px 12px; }
.message.out.group-mid   .message-bubble { border-radius: 12px 4px 4px 12px; }
.message.out.group-last  .message-bubble { border-radius: 12px 4px 12px 12px; }

.message-img {
  max-width: min(280px, 100%);
  height: auto;
  border-radius: 8px;
  display: block;
  cursor: pointer;
}
.message-img.loaded {
  background: none;
}

/* ── DATE SEPARATORS ── */
.date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 8px;
  align-self: stretch;
}
.date-separator::before,
.date-separator::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e4e4e2;
}
.date-separator span {
  font-size: 12px;
  color: #9b9a97;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── MESSAGES LOADER ── */
.messages-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 14px;
  color: #9b9a97;
}

/* ── IMAGE MODAL ── */
.img-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.img-modal.open { display: flex; }

.img-modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: #ffffff;
  font-size: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  line-height: 1;
}
.img-modal-close:hover { background: rgba(255,255,255,0.15); }

.img-modal img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 6px;
  object-fit: contain;
  display: block;
}

/* ── COMPOSER ── */
/* position: relative — нужно для позиционирования templates-popup (absolute child) */
/* На мобильном in-chat position: sticky переопределяется в mobile.css */
.composer {
  flex-shrink: 0;
  padding: 8px 14px 12px;
  border-top: 1px solid #e9e9e7;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  bottom: 0;
  width: 100%;
  box-sizing: border-box;
  max-width: 100vw;
  overflow: visible;
}

.attach-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 0;
}
.attach-preview.visible { display: flex; }

.attach-preview img {
  height: 56px;
  width: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e9e9e7;
}

.attach-cancel {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: #ef4444;
  color: #ffffff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}
.attach-cancel:hover { background: #dc2626; }

.composer-status {
  font-size: 11px;
  color: #9b9a97;
  min-height: 14px;
  padding: 0 4px;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
  width: 100%;
  overflow: hidden;
  position: relative;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  min-height: 42px;
  max-height: 120px;
  resize: none;
  padding: 10px 14px;
  border: 1px solid #e9e9e7;
  border-radius: 20px;
  font-size: 14px;
  font-family: inherit;
  color: #37352f;
  background: #f7f6f3;
  outline: none;
  line-height: 1.4;
  caret-color: #2383e2;
  overflow-y: hidden;
}
.composer textarea.has-scroll {
  overflow-y: auto;
}
.composer textarea::placeholder { color: #b0aeab; opacity: 1; }
.composer textarea:focus {
  border: 1.5px solid #2383e2;
  background: #ffffff;
  outline: none;
}

#sendBtn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: #2383e2;
  color: #ffffff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  font-family: inherit;
}
#sendBtn:hover { background: #1a6fc4; }
#sendBtn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── QUICK REPLIES DROPDOWN ── */
.qr-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}
.qr-btn:hover { background: #f1f1ef; color: #37352f; }

.qr-dropdown {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 13px;
  width: 260px;
  background: #ffffff;
  border: 0.5px solid #e9e9e7;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  z-index: 50;
  overflow: hidden;
}
.qr-dropdown.open { display: block; }

.qr-header {
  padding: 10px 14px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #9b9a97;
  text-transform: uppercase;
}

.qr-list {
  max-height: 220px;
  overflow-y: auto;
}

.qr-item {
  display: flex;
  align-items: center;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13px;
  color: #37352f;
  line-height: 1.4;
  border-bottom: 1px solid #f5f5f4;
  word-break: break-word;
  position: relative;
}
.qr-item:last-child { border-bottom: none; }
.qr-item:hover { background: #f7f6f3; }

.qr-item-text { flex: 1; min-width: 0; }

.qr-item-del {
  display: none;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: 6px;
  padding: 0;
  line-height: 1;
}
.qr-item:hover .qr-item-del { display: flex; }

.qr-add-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #0F4C8A;
  border-top: 1px solid #f0f0ee;
}
.qr-add-row:hover { background: #f7f6f3; }

.qr-add-form {
  padding: 8px 14px 10px;
  border-top: 1px solid #f0f0ee;
}

.qr-new-text {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid #e9e9e7;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  color: #37352f;
  outline: none;
}
.qr-new-text:focus { border-color: #2383e2; }

.qr-form-buttons {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.qr-save-btn {
  padding: 4px 12px;
  font-size: 12px;
  border: 0;
  border-radius: 6px;
  background: #0F4C8A;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
}
.qr-save-btn:hover { background: #0d3f73; }

.qr-cancel-btn {
  padding: 4px 12px;
  font-size: 12px;
  border: 1px solid #e9e9e7;
  border-radius: 6px;
  background: #fff;
  color: #37352f;
  cursor: pointer;
  font-family: inherit;
}
.qr-cancel-btn:hover { background: #f7f6f3; }

/* ── BACK BUTTON ── */
.back-btn { display: none; }

@supports (-webkit-touch-callout: none) {
  .composer {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
