/* ============================================================
   線上客服聊天元件（Chat Widget）
   延續全站高級亮色系 × 精品科技感設計語彙
   ============================================================ */

.chat-widget-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 900;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--gradient-brand);
  box-shadow: var(--shadow-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.chat-widget-launcher:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.chat-widget-launcher svg { width: 26px; height: 26px; }

.chat-widget-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-success);
  box-shadow: 0 0 8px var(--color-success);
  border: 2px solid var(--color-bg-main);
  display: none;
}
.chat-widget-badge.show { display: block; }

.chat-widget-panel {
  position: fixed;
  right: 20px;
  bottom: 90px;
  z-index: 900;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 130px);
  background: #FFFFFF;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-hover);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.chat-widget-panel.open { display: flex; }

.chat-widget-header {
  padding: 16px 18px;
  background: var(--surface-blue);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-widget-header h3 { font-size: 15px; font-weight: 800; color: var(--text-heading); }
.chat-widget-header p { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }
.chat-widget-close {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-secondary);
}
.chat-widget-close:hover { background: var(--bg-blue-soft); color: var(--text-heading); }

.chat-widget-status {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(69, 169, 136, 0.12);
  color: var(--color-success);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
}
.chat-widget-status .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chat-widget-status.offline { background: rgba(217, 105, 105, 0.12); color: var(--color-danger); }

.chat-widget-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-widget-welcome { margin: auto 8px; padding: 20px 14px; text-align: center; color: var(--color-text-secondary); }
.chat-widget-welcome span { display: block; font-size: 28px; margin-bottom: 8px; }
.chat-widget-welcome strong { display: block; color: var(--text-heading); font-size: 14px; }
.chat-widget-welcome p { margin-top: 6px; font-size: 12px; }
.chat-widget-nickname-form { padding: 12px; border-top: 1px solid var(--color-border); }
.chat-widget-nickname-form[hidden], .chat-widget-footer[hidden] { display: none; }
.chat-widget-nickname-form label { display: block; margin-bottom: 7px; color: var(--color-text-secondary); font-size: 12px; }
.chat-widget-nickname-row { display: flex; gap: 8px; }
.chat-widget-nickname-row input { min-width: 0; flex: 1; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-small); color: var(--color-text-primary); }
.chat-widget-nickname-row button { padding: 0 12px; border-radius: var(--radius-small); background: var(--gradient-brand); color: #fff; font-size: 12px; font-weight: 700; }

.chat-msg { max-width: 82%; padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; word-break: break-word; white-space: pre-wrap; }
.chat-msg.visitor { align-self: flex-end; background: var(--gradient-brand); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.agent { align-self: flex-start; background: var(--surface-blue); border: 1px solid var(--color-border); color: var(--color-text-primary); border-bottom-left-radius: 4px; }
.chat-msg.system { align-self: center; background: transparent; color: var(--color-text-muted); font-size: 12px; text-align: center; }
.chat-msg .msg-meta { display: block; font-size: 10.5px; opacity: 0.7; margin-top: 3px; }

.chat-widget-restart {
  margin: 0 14px 12px;
  padding: 9px 14px;
  border-radius: var(--radius-small);
  background: var(--surface-blue);
  border: 1px solid var(--color-border-hover);
  color: var(--color-text-primary);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
.chat-widget-restart:hover { background: var(--bg-blue-soft); }

.chat-widget-footer {
  padding: 12px;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 8px;
}
.chat-widget-input {
  flex: 1;
  resize: none;
  height: 40px;
  max-height: 90px;
  padding: 9px 12px;
  border-radius: var(--radius-small);
  background: #FFFFFF;
  border: 1px solid var(--border-strong);
  color: var(--color-text-primary);
  font-size: 13.5px;
  line-height: 1.4;
}
.chat-widget-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(77, 143, 168, 0.14); }
.chat-widget-input:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-widget-send {
  width: 40px; height: 40px; border-radius: var(--radius-small);
  background: var(--gradient-brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-widget-send svg { width: 18px; height: 18px; }
.chat-widget-send:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-widget-footer {
  background: #f3f5fa;
}
.chat-widget-input {
  background: #eef1f6;
  border-color: #9aa4b5;
  color: #1f2a3d;
}
.chat-widget-send {
  width: 64px;
  background: #37206d;
  border: 1px solid #26154e;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.chat-widget-send:hover:not(:disabled) {
  background: #512d98;
}

/* Keep both chat submission actions readable when page-level form rules load later. */
.chat-widget-panel .chat-widget-nickname-row button,
.chat-widget-panel .chat-widget-send {
  min-width: 64px !important;
  height: 40px !important;
  padding: 0 12px !important;
  border: 1px solid #26154e !important;
  border-radius: var(--radius-small) !important;
  background: #37206d !important;
  color: #fff !important;
  font-size: 13px !important;
  font-weight: 700 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  text-align: center !important;
}
.chat-widget-panel .chat-widget-nickname-row button:hover:not(:disabled),
.chat-widget-panel .chat-widget-send:hover:not(:disabled) {
  background: #512d98 !important;
}
.chat-widget-panel .chat-widget-nickname-row input,
.chat-widget-panel .chat-widget-input {
  background: #eef1f6 !important;
  border-color: #9aa4b5 !important;
  color: #1f2a3d !important;
}

@media (max-width: 480px) {
  .chat-widget-panel { right: 10px; left: 10px; width: auto; bottom: 82px; }
  .chat-widget-launcher { right: 14px; bottom: 14px; }
}
