/* ══════════════════════════════════════
   SPίTI CS WIDGET - cs-widget.css
   版本: 2.0
   加入: 手機版優化、WhatsApp、Email 雙渠道
══════════════════════════════════════ */

:root {
  --cs-teal: #4CCAB8;
  --cs-teal-dark: #3ab5a3;
  --cs-teal-light: #e8faf7;
  --cs-dark: #1a2a27;
  --cs-grey: #6b7c79;
  --cs-light-grey: #f0f4f3;
  --cs-white: #ffffff;
  --cs-danger: #ff6b6b;
  --cs-warning: #ffa94d;
  --cs-whatsapp: #25D366;
}

/* ── FLOATING BUBBLE ── */
.cs-bubble {
  position: fixed;
  bottom: 28px; right: 28px;
  z-index: 9999;
  display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
}

.cs-bubble-btn {
  width: 58px; height: 58px;
  background: var(--cs-teal);
  border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(76,202,184,0.45), 0 2px 8px rgba(0,0,0,0.1);
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s;
  position: relative;
}

.cs-bubble-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(76,202,184,0.55), 0 4px 12px rgba(0,0,0,0.12);
}

.cs-bubble-btn svg { transition: transform 0.3s ease, opacity 0.2s; }
.cs-bubble-btn .icon-chat { position: absolute; }
.cs-bubble-btn .icon-close { position: absolute; opacity: 0; transform: rotate(-90deg); }
.cs-bubble-btn.open .icon-chat { opacity: 0; transform: rotate(90deg); }
.cs-bubble-btn.open .icon-close { opacity: 1; transform: rotate(0deg); }

/* Unread badge */
.cs-unread {
  position: absolute; top: -4px; right: -4px;
  width: 20px; height: 20px;
  background: var(--cs-danger); border-radius: 50%;
  border: 2px solid white;
  font-size: 10px; font-weight: 700; color: white;
  display: flex; align-items: center; justify-content: center;
  animation: cs-pulse-badge 2s ease infinite;
}

@keyframes cs-pulse-badge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* Tooltip */
.cs-tooltip {
  background: var(--cs-dark); color: white;
  padding: 8px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 500;
  white-space: nowrap; font-family: 'Poppins', sans-serif;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  animation: cs-fadeInRight 0.4s ease both;
  cursor: pointer;
}

@keyframes cs-fadeInRight {
  from { opacity: 0; transform: translateX(10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── CHAT WINDOW ── */
.cs-window {
  position: fixed;
  bottom: 100px; right: 28px;
  width: 360px; height: 560px;
  background: var(--cs-white);
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15), 0 4px 20px rgba(76,202,184,0.1);
  display: flex; flex-direction: column;
  overflow: hidden; z-index: 9998;
  transform-origin: bottom right;
  animation: cs-windowOpen 0.3s cubic-bezier(.34,1.3,.64,1) both;
  font-family: 'Poppins', sans-serif;
}

.cs-window.closing {
  animation: cs-windowClose 0.2s ease both;
}

@keyframes cs-windowOpen {
  from { opacity: 0; transform: scale(0.85) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes cs-windowClose {
  from { opacity: 1; transform: scale(1) translateY(0); }
  to   { opacity: 0; transform: scale(0.85) translateY(20px); }
}

/* Header */
.cs-header {
  background: linear-gradient(135deg, var(--cs-dark) 0%, #2d4a44 100%);
  padding: 16px 20px 14px;
  flex-shrink: 0; position: relative; overflow: hidden;
}

.cs-header::before {
  content: ''; position: absolute; top: -30px; right: -30px;
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(76,202,184,0.1);
}

.cs-header-top {
  display: flex; align-items: center; gap: 12px; margin-bottom: 4px;
}

.cs-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--cs-teal);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0; position: relative;
}

.cs-avatar-dot {
  position: absolute; bottom: 1px; right: 1px;
  width: 10px; height: 10px;
  background: #51cf66; border-radius: 50%;
  border: 2px solid var(--cs-dark);
}

.cs-header-info { flex: 1; }

.cs-header-name {
  font-size: 14px; font-weight: 600; color: white; line-height: 1.2;
}

.cs-header-status {
  font-size: 11px; color: rgba(255,255,255,0.55);
  display: flex; align-items: center; gap: 5px;
}

.cs-header-status::before {
  content: ''; width: 6px; height: 6px;
  background: #51cf66; border-radius: 50%;
}

.cs-header-subtitle {
  font-size: 11px; color: rgba(255,255,255,0.4); margin-top: 2px;
}

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

.cs-header-action-btn {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,0.1); border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: white; font-size: 14px;
  transition: background 0.18s;
}

.cs-header-action-btn:hover { background: rgba(255,255,255,0.2); }

/* Quick actions */
.cs-quick-actions {
  display: flex; gap: 6px; padding: 10px 14px;
  border-bottom: 1px solid #edf3f2;
  flex-wrap: wrap; flex-shrink: 0;
  background: #fafefe;
}

.cs-quick-btn {
  border: 1.5px solid #dde8e6; background: white; border-radius: 20px;
  padding: 5px 11px; font-family: 'Poppins', sans-serif;
  font-size: 11px; font-weight: 500; color: var(--cs-grey);
  cursor: pointer; transition: all 0.18s; white-space: nowrap;
}

.cs-quick-btn:hover {
  border-color: var(--cs-teal); color: var(--cs-teal);
  background: var(--cs-teal-light);
}

/* Messages */
.cs-messages {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}

.cs-messages::-webkit-scrollbar { width: 4px; }
.cs-messages::-webkit-scrollbar-track { background: transparent; }
.cs-messages::-webkit-scrollbar-thumb { background: #dde8e6; border-radius: 4px; }

/* Message bubbles */
.cs-msg {
  display: flex; gap: 8px; align-items: flex-end;
  animation: cs-msgIn 0.25s ease both;
}

/* wrapper 控制最大寬度 */
.cs-msg > div:not(.cs-msg-avatar) {
  max-width: calc(100% - 44px);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.cs-msg.user > div:not(.cs-msg-avatar) { align-items: flex-end; }
.cs-msg.bot  > div:not(.cs-msg-avatar) { align-items: flex-start; }

@keyframes cs-msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cs-msg.user { flex-direction: row-reverse; }

.cs-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--cs-teal-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0; flex-grow: 0;
}

.cs-msg.user .cs-msg-avatar {
  background: var(--cs-dark);
  font-size: 11px; color: white; font-weight: 700;
}

.cs-msg-bubble {
  max-width: 100%;
  min-width: 0;
  padding: 10px 14px; border-radius: 16px;
  font-size: 13px; line-height: 1.55;
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: none;
}

.cs-msg.bot .cs-msg-bubble {
  background: var(--cs-light-grey); color: var(--cs-dark);
  border-bottom-left-radius: 4px;
}

.cs-msg.user .cs-msg-bubble {
  background: var(--cs-teal); color: white;
  border-bottom-right-radius: 4px;
}

.cs-msg-time {
  font-size: 10px; color: var(--cs-grey);
  margin-top: 3px; opacity: 0.6;
}

.cs-msg.user .cs-msg-time { text-align: right; }

/* Date divider */
.cs-date-divider {
  text-align: center; font-size: 10px; color: var(--cs-grey);
  display: flex; align-items: center; gap: 8px; opacity: 0.6;
}

.cs-date-divider::before,
.cs-date-divider::after {
  content: ''; flex: 1; height: 1px; background: #dde8e6;
}

/* Typing indicator */
.cs-typing .cs-msg-bubble { padding: 12px 16px; }

.typing-dots {
  display: flex; gap: 4px; align-items: center;
}

.typing-dots span {
  width: 6px; height: 6px;
  background: var(--cs-grey); border-radius: 50%;
  animation: cs-typingDot 1.2s ease infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cs-typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Escalation card */
.cs-escalate-card {
  background: linear-gradient(135deg, #fff9f0, #fff3e0);
  border: 1.5px solid #ffa94d; border-radius: 12px;
  padding: 12px 14px; font-size: 12px; color: #7c4a00;
  margin-top: 4px;
}

.cs-escalate-card strong {
  display: block; margin-bottom: 6px; font-size: 13px;
}

.cs-escalate-btns {
  display: flex; gap: 8px; margin-top: 10px;
}

.cs-escalate-btn {
  flex: 1; padding: 8px 10px; border-radius: 8px; border: none;
  font-family: 'Poppins', sans-serif; font-size: 11px; font-weight: 600;
  cursor: pointer; transition: all 0.18s; display: flex;
  align-items: center; justify-content: center; gap: 5px;
}

.cs-escalate-btn.email {
  background: var(--cs-teal); color: white;
}

.cs-escalate-btn.email:hover { background: var(--cs-teal-dark); }

.cs-escalate-btn.whatsapp {
  background: var(--cs-whatsapp); color: white;
}

.cs-escalate-btn.whatsapp:hover { background: #1fb855; }

.cs-escalate-btn.secondary {
  background: white; color: var(--cs-grey); border: 1px solid #ddd; flex: 0.7;
}

.cs-escalate-btn.secondary:hover { border-color: var(--cs-teal); color: var(--cs-teal); }

/* Input area */
.cs-input-area {
  padding: 10px 14px; border-top: 1px solid #edf3f2;
  display: flex; gap: 8px; align-items: flex-end;
  flex-shrink: 0; background: white;
}

.cs-input {
  flex: 1; border: 1.5px solid #dde8e6; border-radius: 20px;
  padding: 9px 14px; font-family: 'Poppins', sans-serif;
  font-size: 13px; color: var(--cs-dark); background: var(--cs-light-grey);
  resize: none; outline: none;
  min-height: 38px; max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s; line-height: 1.5;
  word-break: break-word; overflow-wrap: break-word;
  white-space: pre-wrap;
}

.cs-input:focus { border-color: var(--cs-teal); background: white; }
.cs-input::placeholder { color: #adb8b6; }

.cs-send-btn {
  width: 38px; height: 38px; flex-shrink: 0;
  background: var(--cs-teal); border: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s;
}

.cs-send-btn:hover { background: var(--cs-teal-dark); transform: scale(1.05); }
.cs-send-btn:disabled { background: #dde8e6; cursor: not-allowed; transform: none; }

/* Footer */
.cs-footer {
  padding: 7px; text-align: center;
  font-size: 10px; color: #c0cac9; font-family: 'Poppins', sans-serif;
  border-top: 1px solid #f0f4f3; flex-shrink: 0;
}

.cs-footer a { color: var(--cs-teal); text-decoration: none; }

/* ── MOBILE ── */
@media (max-width: 480px) {
  .cs-window {
    right: 0; bottom: 0; left: 0;
    width: 100%; height: 88vh;
    border-radius: 24px 24px 0 0;
    bottom: 0 !important;
  }

  .cs-bubble {
    bottom: 80px; right: 20px;
  }

  .cs-msg-bubble { max-width: 82%; }

  .cs-escalate-btns { flex-direction: column; }
  .cs-escalate-btn.secondary { flex: 1; }
}

@media (max-width: 360px) {
  .cs-quick-actions { gap: 4px; }
  .cs-quick-btn { font-size: 10px; padding: 4px 9px; }
}

/* ══════════════════════════════════════
   訂單進度條 (v3.1)
══════════════════════════════════════ */

/* 進度條外框 */
.cs-order-progress {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin: 12px 0 6px;
  padding: 10px 6px 6px;
  background: rgba(76,202,184,0.07);
  border-radius: 10px;
  border: 1px solid rgba(76,202,184,0.18);
  position: relative;
}

/* 每個步驟的容器 */
.cs-step-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
  min-width: 48px;
  z-index: 1;
}

/* 步驟圓點 */
.cs-step {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  border: 2px solid #cbd5e1;
  background: #f8fafc;
  color: #94a3b8;
  transition: all 0.3s ease;
  margin-bottom: 5px;
}

.cs-step.done {
  background: #4CCAB8;
  border-color: #4CCAB8;
  color: #fff;
  font-size: 13px;
}

.cs-step.active {
  background: #fff;
  border-color: #4CCAB8;
  color: #4CCAB8;
  box-shadow: 0 0 0 3px rgba(76,202,184,0.2);
}

/* 步驟標籤 */
.cs-step-label {
  font-size: 9.5px;
  color: #94a3b8;
  text-align: center;
  white-space: nowrap;
  line-height: 1.2;
}

.cs-step.done + .cs-step-label,
.cs-step-wrap:has(.cs-step.done) .cs-step-label,
.cs-step-wrap:has(.cs-step.active) .cs-step-label {
  color: #4CCAB8;
  font-weight: 600;
}

/* 連接線 */
.cs-step-line {
  flex: 1;
  height: 2px;
  background: #e2e8f0;
  margin-top: 13px;  /* 對齊圓點中心 */
  align-self: flex-start;
  transition: background 0.3s ease;
  min-width: 8px;
}

.cs-step-line.done {
  background: #4CCAB8;
}

/* SPX 追蹤連結 */
.cs-track-link {
  color: #4CCAB8 !important;
  text-decoration: underline;
  font-weight: 600;
  word-break: break-all;
}

.cs-track-link:hover {
  color: #3ab8a6 !important;
}

/* 完成訊息 */
.cs-order-completed {
  font-size: 12px;
  color: #4CCAB8;
  font-weight: 600;
  margin: 6px 0 2px;
  text-align: center;
}

/* 底部小字 */
.cs-order-footer {
  font-size: 11px;
  opacity: 0.6;
  margin-top: 8px;
}