/* =========================================================================
   Temporary Online Support Chat Widget — Warm Editorial Style + Mobile Sheet
   Strict CSP safe (zero inline styles). Adapts to GPT (emerald) & Claude (terracotta).
   ========================================================================= */
:root {
  --cw-accent: #2f6f53;
  --cw-accent-dark: #21513b;
  --cw-accent-grad: linear-gradient(135deg, #2f6f53 0%, #235740 100%);
  --cw-accent-soft: #eaf4ee;
  --cw-accent-border: #b6d4c3;
  --cw-accent-shadow: rgba(35, 87, 64, 0.28);
  --cw-paper: #ffffff;
  --cw-bg: #faf8f4;
  --cw-line: #e8e1d7;
  --cw-ink: #24211e;
  --cw-muted: #7f776d;
}

body[data-chat-source="claude"] {
  --cw-accent: #c4593b;
  --cw-accent-dark: #a14328;
  --cw-accent-grad: linear-gradient(135deg, #c95f40 0%, #ab482c 100%);
  --cw-accent-soft: #fcf0ea;
  --cw-accent-border: #e5bfb0;
  --cw-accent-shadow: rgba(185, 96, 68, 0.28);
}

.cw-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--cw-accent-dark);
  background: var(--cw-accent-grad);
  color: #fff;
  font-family: "Microsoft YaHei", "PingFang SC", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 10px 28px var(--cw-accent-shadow);
  cursor: pointer;
  transition: transform .16s, box-shadow .18s;
}

.cw-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px var(--cw-accent-shadow);
}

.cw-launcher:active {
  transform: scale(0.97);
}

.cw-launcher svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.cw-launcher-badge,
.cw-inline-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #d94136;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(217, 65, 54, 0.35);
}

.cw-inline-badge {
  margin-left: 7px;
}

/* Desktop already has a prominent sidebar "在线联系客服" button; avoid overlapping bottom-right submit CTA */
@media (min-width: 761px) {
  .cw-launcher {
    display: none;
  }
}

.cw-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  width: min(392px, calc(100vw - 32px));
  height: min(580px, calc(100dvh - 48px));
  display: flex;
  flex-direction: column;
  background: var(--cw-paper);
  border: 1px solid #e4dcd0;
  border-radius: 24px;
  box-shadow: 0 24px 70px rgba(36, 33, 30, 0.18);
  overflow: hidden;
  font-family: "Microsoft YaHei", "PingFang SC", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  color: var(--cw-ink);
  animation: cwPop .18s ease;
}

@keyframes cwPop {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.cw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 15px 16px 14px 18px;
  background: var(--cw-accent-grad);
  color: #fff;
  flex-shrink: 0;
}

.cw-header-info {
  min-width: 0;
}

.cw-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.cw-header-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  padding: 2px;
  object-fit: contain;
  flex: none;
}

.cw-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8ff0b8;
  flex: none;
}

.cw-header-sub {
  margin-top: 3px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.84);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cw-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.cw-header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}

.cw-header-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.cw-close-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.cw-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 14px;
  background: var(--cw-bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.cw-system-note {
  align-self: center;
  max-width: 92%;
  padding: 6px 12px;
  border-radius: 999px;
  background: #eee9e0;
  color: #6e675e;
  font-size: 11px;
  text-align: center;
  line-height: 1.5;
}

.cw-msg {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  gap: 4px;
}

.cw-msg.client {
  align-self: flex-end;
  align-items: flex-end;
}

.cw-msg.admin {
  align-self: flex-start;
  align-items: flex-start;
}

.cw-bubble {
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.cw-msg.admin .cw-bubble {
  background: #ffffff;
  border: 1px solid #e6dfd5;
  color: var(--cw-ink);
  border-bottom-left-radius: 5px;
  box-shadow: 0 2px 6px rgba(36, 33, 30, 0.04);
}

.cw-msg.client .cw-bubble {
  background: var(--cw-accent-grad);
  color: #ffffff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 3px 10px var(--cw-accent-shadow);
}

.cw-msg-img-btn {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  margin-top: 6px;
}

.cw-bubble-img-only {
  padding: 5px;
}

.cw-bubble-img-only .cw-msg-img-btn {
  margin-top: 0;
}

.cw-msg-img {
  display: block;
  max-width: 210px;
  max-height: 220px;
  width: auto;
  height: auto;
  border-radius: 11px;
  object-fit: cover;
}

.cw-msg-meta {
  font-size: 10.5px;
  color: #9b9388;
  padding: 0 4px;
  font-variant-numeric: tabular-nums;
}

.cw-error {
  margin: 0;
  padding: 8px 14px;
  background: #fdf0ee;
  border-top: 1px solid #f0d2cd;
  color: #a63d2d;
  font-size: 12px;
  flex-shrink: 0;
}

.cw-preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: #f5f1ea;
  border-top: 1px solid var(--cw-line);
  flex-shrink: 0;
}

.cw-preview-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.cw-preview-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid #ddd4c7;
  flex: none;
}

.cw-preview-label {
  font-size: 12px;
  color: #5c554c;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cw-preview-remove {
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid #d9cfc0;
  background: #fff;
  color: #6b645b;
  font-size: 11.5px;
  cursor: pointer;
  flex: none;
}

.cw-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #ffffff;
  border-top: 1px solid var(--cw-line);
  flex-shrink: 0;
}

.cw-file-input {
  display: none;
}

.cw-img-btn {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  border: 1px solid #ddd5c9;
  background: #f8f5f0;
  color: #524b42;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
  transition: background .15s, border-color .15s, color .15s;
}

.cw-img-btn:hover {
  background: var(--cw-accent-soft);
  border-color: var(--cw-accent-border);
  color: var(--cw-accent-dark);
}

.cw-img-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cw-input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 110px;
  padding: 9px 12px;
  border: 1px solid var(--cw-line);
  border-radius: 12px;
  background: #f7f5f1;
  color: var(--cw-ink);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  resize: none;
  outline: none;
}

.cw-input:focus {
  border-color: var(--cw-accent);
  background: #fff;
}

.cw-send-btn {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--cw-accent-dark);
  border-radius: 11px;
  background: var(--cw-accent-grad);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  flex: none;
  transition: opacity .15s, transform .14s;
}

.cw-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cw-send-btn:not(:disabled):active {
  transform: scale(0.97);
}

/* Lightbox Dialog */
.cw-lightbox {
  padding: 0;
  border: 0;
  background: transparent;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  overflow: visible;
}

.cw-lightbox::backdrop {
  background: rgba(20, 18, 16, 0.78);
  backdrop-filter: blur(4px);
}

.cw-lightbox-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cw-lightbox-img {
  display: block;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 88px);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  background: #fff;
}

.cw-lightbox-close {
  margin-top: 12px;
  min-height: 38px;
  padding: 6px 20px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

body.cw-mobile-open {
  overflow: hidden;
}

@media (max-width: 600px) {
  .cw-launcher {
    right: 14px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    min-height: 46px;
    padding: 0 16px;
    font-size: 13px;
  }

  .cw-panel {
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: 0;
  }

  .cw-header {
    padding: calc(14px + env(safe-area-inset-top)) 14px 13px 16px;
  }

  .cw-input {
    font-size: 16px;
  }

  .cw-img-btn,
  .cw-send-btn {
    min-height: 42px;
  }

  .cw-img-btn {
    width: 42px;
    height: 42px;
  }

  /* Leave comfortable clearance at bottom of mobile pages for the floating pill */
  body[data-chat-source] .frame {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }
}
