/* ===================================
   南丁卫校智能客服 - 侧边栏样式
   =================================== */

:root {
  --nd-primary: #1a56db;
  --nd-primary-light: #e8f0fe;
  --nd-primary-hover: #1647b8;
  --nd-success: #057a55;
  --nd-success-light: #def7ec;
  --nd-bg: #ffffff;
  --nd-bg-chat: #f7f8fa;
  --nd-bg-bubble-ai: #f0f4f8;
  --nd-bg-bubble-user: #1a56db;
  --nd-text: #1f2937;
  --nd-text-light: #6b7280;
  --nd-text-white: #ffffff;
  --nd-border: #e5e7eb;
  --nd-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --nd-radius: 12px;
  --nd-radius-sm: 8px;
  --nd-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 遮罩层 */
.nd-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 999998;
  opacity: 0;
  visibility: hidden;
  transition: var(--nd-transition);
}
.nd-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* 侧边栏容器 */
.nd-chat-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: var(--nd-bg);
  box-shadow: var(--nd-shadow);
  z-index: 999999;
  display: flex;
  flex-direction: column;
  transform: translateX(110%);
  transition: var(--nd-transition);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.nd-chat-sidebar.open {
  transform: translateX(0);
}

/* 触发按钮 */
.nd-trigger-wrapper {
  position: fixed;
  right: 20px;
  top: 35%;
  transform: translateY(-50%);
  z-index: 999997;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.nd-trigger-wrapper.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.nd-trigger-btn {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: var(--nd-primary);
  color: var(--nd-text-white);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(26, 86, 219, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--nd-transition);
  animation: nd-pulse 2s infinite;
  padding: 0;
  overflow: hidden;
}
.nd-trigger-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(26, 86, 219, 0.5);
}
.nd-trigger-label {
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  padding: 4px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 1px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.nd-trigger-btn svg {
  display: none;
}
.nd-trigger-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid white;
  animation: nd-badge-pulse 3s infinite;
}
@keyframes nd-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(26, 86, 219, 0.4); }
  50% { box-shadow: 0 4px 24px rgba(26, 86, 219, 0.65); }
}
@keyframes nd-badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ===== 侧边栏内部组件 ===== */

/* 头部 */
.nd-header {
  background: linear-gradient(135deg, #1a56db, #1e40af);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.nd-header-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.nd-header-info {
  flex: 1;
  min-width: 0;
}
.nd-header-title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}
.nd-header-subtitle {
  font-size: 12px;
  opacity: 0.85;
  line-height: 1.3;
  display: flex;
  align-items: center;
  gap: 4px;
}
.nd-header-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
  animation: nd-dot-pulse 2s infinite;
}
@keyframes nd-dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.nd-close-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  font-size: 18px;
}
.nd-close-btn:hover {
  background: rgba(255,255,255,0.25);
}

/* 消息区域 */
.nd-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--nd-bg-chat);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.nd-messages::-webkit-scrollbar {
  width: 4px;
}
.nd-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

/* 消息气泡 */
.nd-msg {
  display: flex;
  gap: 8px;
  max-width: 90%;
  animation: nd-msg-in 0.3s ease-out;
}
@keyframes nd-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.nd-msg.ai {
  align-self: flex-start;
}
.nd-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.nd-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.nd-msg.ai .nd-msg-avatar {
  background: var(--nd-primary-light);
  color: var(--nd-primary);
}
.nd-msg.user .nd-msg-avatar {
  background: #dbeafe;
  color: #1e40af;
}
.nd-msg-bubble {
  padding: 10px 14px;
  border-radius: var(--nd-radius-sm);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}
.nd-msg.ai .nd-msg-bubble {
  background: var(--nd-bg-bubble-ai);
  color: var(--nd-text);
  border-top-left-radius: 2px;
}
.nd-msg.user .nd-msg-bubble {
  background: var(--nd-bg-bubble-user);
  color: var(--nd-text-white);
  border-top-right-radius: 2px;
}

/* 打字指示器 */
.nd-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.nd-typing-dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--nd-bg-bubble-ai);
  border-radius: var(--nd-radius-sm);
  border-top-left-radius: 2px;
}
.nd-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: nd-bounce 1.4s infinite ease-in-out both;
}
.nd-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.nd-typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.nd-typing-dots span:nth-child(3) { animation-delay: 0s; }
@keyframes nd-bounce {
  0%, 80%, 100% { transform: scale(0.6); }
  40% { transform: scale(1); }
}

/* 快捷按钮 */
.nd-quick-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
}
.nd-quick-btn {
  padding: 7px 14px;
  border: 1px solid var(--nd-border);
  border-radius: 18px;
  font-size: 13px;
  color: var(--nd-primary);
  background: white;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.nd-quick-btn:hover {
  background: var(--nd-primary-light);
  border-color: var(--nd-primary);
}

/* 留资表单卡片 */
.nd-lead-card {
  background: white;
  border: 1.5px solid #fbbf24;
  border-radius: var(--nd-radius);
  padding: 16px;
  margin: 8px 0;
  box-shadow: 0 2px 12px rgba(251, 191, 36, 0.12);
}
.nd-lead-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--nd-text);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.nd-lead-card-subtitle {
  font-size: 12px;
  color: var(--nd-text-light);
  margin-bottom: 12px;
}
.nd-lead-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--nd-border);
  border-radius: var(--nd-radius-sm);
  font-size: 14px;
  margin-bottom: 8px;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
  font-family: inherit;
}
.nd-lead-input:focus {
  border-color: var(--nd-primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}
.nd-lead-input::placeholder {
  color: #9ca3af;
}
.nd-lead-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--nd-border);
  border-radius: var(--nd-radius-sm);
  font-size: 14px;
  margin-bottom: 8px;
  outline: none;
  background: white;
  cursor: pointer;
  box-sizing: border-box;
  font-family: inherit;
  color: var(--nd-text);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.nd-lead-select:focus {
  border-color: var(--nd-primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}
.nd-lead-submit {
  width: 100%;
  padding: 11px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  border: none;
  border-radius: var(--nd-radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.nd-lead-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.35);
}
.nd-lead-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}
.nd-lead-agreement {
  font-size: 11px;
  color: var(--nd-text-light);
  text-align: center;
  margin-top: 8px;
  line-height: 1.4;
}

/* 成功提示 */
.nd-success-card {
  text-align: center;
  padding: 20px;
  background: var(--nd-success-light);
  border-radius: var(--nd-radius);
  margin: 8px 0;
}
.nd-success-icon {
  width: 48px;
  height: 48px;
  background: var(--nd-success);
  border-radius: 50%;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 24px;
}
.nd-success-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--nd-text);
  margin-bottom: 4px;
}
.nd-success-desc {
  font-size: 13px;
  color: var(--nd-text-light);
}

/* 输入区域 */
.nd-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--nd-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: white;
}
.nd-input-field {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--nd-border);
  border-radius: 22px;
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 100px;
  font-family: inherit;
  transition: border-color 0.2s;
}
.nd-input-field:focus {
  border-color: var(--nd-primary);
}
.nd-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--nd-primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.nd-send-btn:hover {
  background: var(--nd-primary-hover);
  transform: scale(1.05);
}
.nd-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.nd-send-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

/* 响应式 - 移动端全屏 */
@media (max-width: 767px) {
  .nd-chat-sidebar {
    width: 100vw;
    border-radius: 0;
  }
  .nd-trigger-wrapper {
    right: 12px;
    top: 30%;
  }
  .nd-trigger-btn {
    width: 100px;
    height: 100px;
  }
  .nd-trigger-label {
    font-size: 11px;
    padding: 3px 10px;
  }
}
