/* 智能客服浮窗 */
.chat-widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1001;
  font-family: inherit;
  --chat-theme: var(--green, #1a7a4c);
  --chat-theme-dark: var(--green-dark, #0f5c38);
}

.chat-widget.chat-left {
  right: auto;
  left: 24px;
}

.chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 46, 36, 0.35);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
  backdrop-filter: blur(2px);
}

.chat-backdrop.visible {
  opacity: 1;
  visibility: visible;
}

body.chat-open {
  overflow: hidden;
}

.chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--chat-theme) 0%, var(--chat-theme-dark) 100%);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.chat-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px color-mix(in srgb, var(--chat-theme) 35%, transparent);
}

.chat-widget.is-open .chat-toggle {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}

/* 固定于视口，保证完整可见 */
.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 88px;
  top: 12px;
  width: min(400px, calc(100vw - 32px));
  max-height: none;
  height: auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--chat-theme) 12%, transparent);
  z-index: 1002;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.25s, transform 0.25s, visibility 0.25s;
}

.chat-widget.chat-left .chat-panel {
  right: auto;
  left: 24px;
}

.chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chat-panel:not(.is-open) {
  pointer-events: none;
}

.chat-header {
  background: linear-gradient(135deg, var(--chat-theme) 0%, var(--chat-theme-dark) 100%);
  color: #fff;
  padding: 14px 16px 12px;
  flex-shrink: 0;
}

.chat-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.chat-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  flex: 1;
  padding-right: 4px;
}

.chat-header p {
  margin: 0;
  font-size: 12px;
  opacity: 0.92;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chat-learn-tag {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 10px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  font-size: 11px;
}

.chat-close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background 0.2s;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.35);
}

.chat-close-text {
  font-size: 12px;
  font-weight: 500;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  background: #f7faf8;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.chat-msg {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--chat-theme);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.bot {
  align-self: flex-start;
  background: #fff;
  color: var(--dark);
  border: 1px solid #e5ebe7;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.chat-msg-body {
  flex: 1;
  min-width: 0;
}

.chat-msg.typing {
  color: #888;
  font-style: italic;
}

.chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: #fff;
  border-top: 1px solid #eef2ef;
  flex-shrink: 0;
  max-height: 88px;
  overflow-y: auto;
}

.chat-quick button {
  border: 1px solid color-mix(in srgb, var(--chat-theme) 20%, #fff);
  background: color-mix(in srgb, var(--chat-theme) 8%, #fff);
  color: var(--chat-theme-dark);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}

.chat-quick button:hover {
  background: var(--chat-theme);
  color: #fff;
  border-color: var(--chat-theme);
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #eef2ef;
  flex-shrink: 0;
}

.chat-input-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}

.chat-input-row input:focus {
  border-color: var(--chat-theme);
}

.chat-input-row button {
  flex-shrink: 0;
  padding: 0 16px;
  border: none;
  border-radius: 8px;
  background: var(--chat-theme);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

.chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.chat-input-row button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-panel-footer {
  flex-shrink: 0;
  padding: 6px 12px 10px;
  text-align: center;
  background: #fff;
  border-top: 1px solid #eef2ef;
}

.chat-panel-footer button {
  border: none;
  background: none;
  color: var(--gray-500, #6b7c72);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
}

.chat-panel-footer button:hover {
  color: var(--chat-theme);
}

/* 聊天报价单操作 */
.chat-msg-quote .chat-quote-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed rgba(26, 122, 76, 0.25);
  position: relative;
  z-index: 1;
}

.chat-quote-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border: 1px solid #c5d9ce;
  border-radius: 999px;
  background: #fff;
  color: var(--chat-theme-dark, #0f5c38);
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.chat-quote-btn:hover {
  background: #f0f8f4;
  border-color: var(--chat-theme);
}

.chat-quote-btn-primary {
  background: var(--chat-theme);
  border-color: var(--chat-theme);
  color: #fff;
}

.chat-quote-btn-primary:hover {
  background: var(--chat-theme-dark);
  border-color: var(--chat-theme-dark);
}

.chat-quote-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.chat-quote-btn-link {
  border-style: dashed;
}

/* 报价单弹层 */
.chat-quote-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.chat-quote-modal.hidden {
  display: none;
}

body.chat-quote-modal-open {
  overflow: hidden;
}

.chat-quote-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 46, 36, 0.55);
  backdrop-filter: blur(2px);
}

.chat-quote-modal-dialog {
  position: relative;
  width: min(960px, 100%);
  max-height: min(92vh, 900px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-quote-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #eef2ef;
  background: #f8fbf9;
  flex-shrink: 0;
}

.chat-quote-modal-header h4 {
  margin: 0;
  font-size: 16px;
  color: var(--chat-theme-dark, #0f5c38);
}

.chat-quote-modal-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-quote-modal-body {
  overflow: auto;
  padding: 16px;
  flex: 1;
}

.chat-quote-sheet,
.chat-quote-print-root .chat-quote-sheet {
  font-size: 13px;
  color: #243329;
  line-height: 1.5;
}

.chat-quote-sheet .sq-letterhead,
.chat-quote-print-root .sq-letterhead {
  margin: 0 0 14px;
  padding: 14px 16px;
  border-bottom: 2px solid #dde8e2;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, #f8fbf9 0%, #fff 100%);
}

.chat-quote-sheet .sq-letterfoot,
.chat-quote-print-root .sq-letterfoot {
  margin: 14px 0 0;
  padding: 14px 16px 0;
  border-top: 2px solid #dde8e2;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, #fff 0%, #f8fbf9 100%);
}

.chat-quote-sheet .sq-brand-row,
.chat-quote-print-root .sq-brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-quote-sheet .sq-brand-row--foot,
.chat-quote-print-root .sq-brand-row--foot {
  justify-content: center;
}

.chat-quote-sheet .sq-brand-logo,
.chat-quote-print-root .sq-brand-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
  background: #fff;
  padding: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.chat-quote-sheet .sq-brand-company,
.chat-quote-print-root .sq-brand-company {
  display: block;
  font-size: 17px;
  font-weight: 700;
  color: var(--chat-theme-dark, #0f5c38);
  line-height: 1.3;
}

.chat-quote-sheet .sq-brand-sub,
.chat-quote-print-root .sq-brand-sub {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: #5a6b62;
}

.chat-quote-sheet .sq-foot-contact,
.chat-quote-print-root .sq-foot-contact {
  margin: 6px 0 0;
  font-size: 11px;
  color: #5a6b62;
}

.chat-quote-sheet .sq-foot-note,
.chat-quote-print-root .sq-foot-note {
  margin: 10px 0 0;
  padding-top: 8px;
  border-top: 1px dashed #dde8e2;
  font-size: 11px;
  color: #7a9084;
  text-align: center;
}

.chat-quote-sheet .sq-contact-block,
.chat-quote-print-root .sq-contact-block {
  font-size: 12px;
  color: #5a6b62;
  text-align: right;
  min-width: 200px;
}

.chat-quote-sheet .sq-contact-block a,
.chat-quote-print-root .sq-contact-block a {
  color: var(--chat-theme);
  text-decoration: none;
}

.cqs-header.sq-sheet-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #eef2ef;
}

.cqs-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.cqs-header h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: var(--chat-theme-dark, #0f5c38);
}

.cqs-meta,
.cqs-buyer,
.cqs-host,
.cqs-flow {
  margin: 0 0 4px;
  font-size: 12px;
  color: #5a6b62;
}

.cqs-warnings {
  margin-bottom: 10px;
  padding: 8px 10px;
  background: #fff8e6;
  border: 1px solid #f0dfa8;
  border-radius: 8px;
  font-size: 12px;
  color: #8a6d1a;
}

.cqs-table-wrap {
  overflow-x: auto;
  margin-bottom: 12px;
}

.cqs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.cqs-table th,
.cqs-table td {
  padding: 8px 6px;
  border: 1px solid #dde8e2;
  vertical-align: top;
}

.cqs-table th {
  background: #edf7f1;
  color: var(--chat-theme-dark, #0f5c38);
  font-weight: 600;
  white-space: nowrap;
}

.cqs-desc-col { max-width: 180px; }
.cqs-qty-col { text-align: center; white-space: nowrap; }
.cqs-amount { text-align: right; font-weight: 600; white-space: nowrap; }
.cqs-total-label { text-align: right; font-weight: 600; }
.cqs-grand-total td { background: #f3faf6; }
.cqs-auto-tag { color: #7a9084; font-size: 10px; }
.cqs-desc { font-size: 11px; color: #5a6b62; }

.cqs-cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.cqs-cat-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: #f8fbf9;
  border-radius: 8px;
  font-size: 12px;
}

.cqs-terms {
  margin: 0 0 12px;
  padding-left: 18px;
  font-size: 11px;
  color: #5a6b62;
}

.cqs-footer {
  margin: 0;
  font-size: 11px;
  color: #7a9084;
  text-align: center;
}

.chat-quote-print-root {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

body.chat-quote-pdf-export .chat-quote-modal-toolbar,
body.chat-quote-pdf-export .chat-quote-modal-header h4 {
  visibility: hidden;
}

body.chat-quote-pdf-export .sq-letterhead,
body.chat-quote-pdf-export .sq-letterfoot {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

@media print {
  body.chat-quote-printing > *:not(#chatQuotePrintRoot) {
    display: none !important;
  }

  body.chat-quote-printing #chatQuotePrintRoot {
    display: block !important;
    position: static !important;
    left: auto !important;
    width: auto !important;
    height: auto !important;
    opacity: 1 !important;
    overflow: visible !important;
    pointer-events: auto !important;
  }

  body.chat-quote-printing .cqs-table { font-size: 10px; }
}

@media (max-width: 480px) {
  .cqs-header { flex-direction: column; }
  .cqs-seller { text-align: left; min-width: 0; }
  .chat-quote-modal-toolbar { width: 100%; justify-content: flex-end; }
}

@media (max-width: 480px) {
  .chat-widget,
  .chat-widget.chat-left {
    right: 12px;
    left: auto;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .chat-widget.chat-left {
    left: 12px;
    right: auto;
  }

  .chat-panel,
  .chat-widget.chat-left .chat-panel {
    right: 8px;
    left: 8px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    top: max(12px, env(safe-area-inset-top, 12px));
    width: auto;
    border-radius: 14px;
  }

  .float-phone {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    right: 12px;
  }

  .chat-toggle {
    width: 52px;
    height: 52px;
  }
}
