/* ============================================================
   极客数码 - 客服系统全局样式
   ============================================================ */

:root {
  --primary:        #6366f1;
  --primary-dark:   #4f46e5;
  --primary-light:  #eef2ff;
  --bg:             #f5f5f7;
  --sidebar-bg:     #ffffff;
  --chat-bg:        #f0f2f5;
  --card-bg:        #ffffff;
  --text-main:      #1d1d1f;
  --text-secondary: #6e6e73;
  --text-muted:     #999;
  --border:         #e5e7eb;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.06);
  --shadow-md:      0 4px 12px rgba(0,0,0,.08);
  --shadow-lg:      0 8px 30px rgba(0,0,0,.12);
  --radius-sm:      8px;
  --radius-md:      12px;
  --radius-lg:      16px;
  --radius-xl:      24px;
  --tag-hot:        #ef4444;
  --tag-new:        #10b981;
  --price-color:    #e9334b;
}

/* ========== Reset ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial,
               sans-serif;
  background: var(--bg);
  color: var(--text-main);
  /* 移动端 vh 不准确 → 使用 dvh + -webkit-fill-available 确保填满可视区域 */
  height: 100vh;
  height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

button {
  cursor: pointer;
  border: none;
  font-family: inherit;
}

input { font-family: inherit; }

/* ========== 顶部栏 ========== */
.top-bar {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #3730a3 100%);
  color: #fff;
  flex-shrink: 0;
  z-index: 100;
}
.top-bar-inner {
  max-width: 100%;
  margin: 0 auto;
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-icon { font-size: 22px; }
.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand-badge {
  font-size: 11px;
  background: rgba(255,255,255,.2);
  padding: 2px 8px;
  border-radius: 10px;
}
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 13px;
}
.top-tag { opacity: .85; }
.service-time {
  opacity: .7;
  font-size: 12px;
}

/* ========== 主体 ========== */
.main-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 52px);
  height: calc(100dvh - 52px);
  min-height: 0;            /* flex 子项允许收缩 */
  overflow: hidden;
}

/* ========== 商品侧栏 ========== */
.product-sidebar {
  width: 380px;
  min-width: 380px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 10;
}
.sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-header h2 {
  font-size: 16px;
  margin-bottom: 10px;
  color: var(--text-main);
}
.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cat-tab {
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 12px;
  background: var(--bg);
  color: var(--text-secondary);
  transition: all .2s;
  border: 1px solid transparent;
}
.cat-tab:hover {
  background: var(--primary-light);
  color: var(--primary);
}
.cat-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* 商品列表 */
.product-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}
.product-list::-webkit-scrollbar { width: 4px; }
.product-list::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 4px;
}

/* 商品卡片 */
.product-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  margin-bottom: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all .2s;
  position: relative;
  overflow: hidden;
}
.product-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.product-card:active {
  transform: scale(.98);
}
.product-card-img {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: #f3f4f6;
  flex-shrink: 0;
}
.product-card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}
.product-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-card-tags {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.tag-hot { background: #fef2f2; color: var(--tag-hot); }
.tag-new { background: #ecfdf5; color: var(--tag-new); }
.product-card-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.product-card-price {
  font-size: 18px;
  font-weight: 700;
  color: var(--price-color);
}
.product-card-price::before { content: '¥'; font-size: 12px; }
.product-card-original {
  font-size: 11px;
  color: var(--text-muted);
  text-decoration: line-through;
}
.product-card-desc {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.product-card-sales {
  font-size: 10px;
  color: var(--text-muted);
}

/* 侧栏底部 */
.sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  text-align: center;
}
.sidebar-footer p {
  font-size: 12px;
  color: var(--text-muted);
}

/* ========== 客服聊天区 ========== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  min-width: 0;
  min-height: 0;            /* 避免被内容撑开而不收缩 */
}

/* 聊天头部 */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar {
  position: relative;
  width: 42px;
  height: 42px;
}
.avatar img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #ffe4e6;
  object-fit: cover;
}
.online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: #22c55e;
  border: 2px solid #fff;
  border-radius: 50%;
}
.chat-header-info h3 {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.role-badge {
  font-size: 10px;
  font-weight: 500;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
}
.chat-header-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.header-btn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  transition: all .15s;
}
.header-btn:hover { background: #fee2e2; color: #ef4444; }

/* 语言选择器 */
.lang-selector {
  position: relative;
  margin-right: 6px;
}
.lang-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 12px;
  transition: all .15s;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.lang-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.lang-arrow {
  font-size: 8px;
  margin-left: 2px;
  opacity: .6;
}
.lang-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 200px;
  max-height: 280px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 200;
}
.lang-dropdown.show {
  display: block;
}
.lang-option {
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
  transition: background .12s;
  white-space: nowrap;
}
.lang-option:hover {
  background: var(--primary-light);
  color: var(--primary);
}
.lang-option.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
.lang-dropdown::-webkit-scrollbar { width: 4px; }
.lang-dropdown::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 4px;
}

/* 消息区域 */
.chat-messages {
  flex: 1;
  min-height: 0;            /* flex 子项收缩关键：释放空间给输入区 */
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

/* 系统消息 */
.msg-system {
  text-align: center;
  margin: 4px 0;
}
.msg-system span {
  display: inline-block;
  padding: 4px 12px;
  background: #fff;
  border-radius: 10px;
  font-size: 11px;
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
}

/* 消息行 */
.msg-row {
  display: flex;
  gap: 10px;
  max-width: 85%;
}
.msg-row.msg-assistant {
  align-self: flex-start;
}
.msg-row.msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
}
.msg-avatar img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ffe4e6;
  object-fit: cover;
}
.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  position: relative;
}
.msg-assistant .msg-bubble {
  background: #fff;
  border-top-left-radius: 4px;
  box-shadow: var(--shadow-sm);
  color: var(--text-main);
}
.msg-user .msg-bubble {
  background: var(--primary);
  color: #fff;
  border-top-right-radius: 4px;
  box-shadow: var(--shadow-sm);
}
/* 气泡内图片 */
.msg-bubble img {
  max-width: 120px;
  border-radius: 6px;
  margin-top: 4px;
}

/* 正在输入动画 */
.msg-typing .msg-bubble {
  display: flex;
  gap: 4px;
  padding: 14px 18px;
}
.typing-dot {
  width: 7px;
  height: 7px;
  background: #aaa;
  border-radius: 50%;
  animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* 输入区 */
.chat-input-area {
  padding: 12px 20px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  background: #fff;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  font-size: 14px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  background: var(--bg);
}
.chat-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
  background: #fff;
}
.chat-input::placeholder {
  color: var(--text-muted);
}
.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  flex-shrink: 0;
}
.send-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}
.send-btn:active { transform: scale(.95); }
.send-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}
.send-icon { font-size: 16px; margin-left: 2px; }
.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  text-align: center;
}

/* ========== 响应式 ========== */
@media (max-width: 900px) {
  .product-sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: 35%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    overflow-y: auto;
  }
  .main-container {
    flex-direction: column;
    /* 移动端动态视口高度，消除地址栏/工具栏影响 */
    height: 100vh;
    height: 100dvh;
  }
  .chat-area {
    min-height: 0;
    flex: 1;
  }
  .chat-messages {
    flex: 1;
    min-height: 0;
  }
  .chat-input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  }
  .top-bar-right { display: none; }
  /* 顶部栏移动端优化 */
  .top-bar-inner {
    padding: 0 12px;
    height: 44px;
  }
  .brand-name { font-size: 15px; }
  .brand-badge { display: none; }
  .service-time { display: none; }
  /* 侧栏头部紧凑 */
  .sidebar-header {
    padding: 10px 12px 8px;
  }
  .sidebar-header h2 {
    font-size: 14px;
    margin-bottom: 6px;
  }
  .cat-tab {
    padding: 4px 8px;
    font-size: 11px;
  }
  /* 商品卡片紧凑 */
  .product-card {
    padding: 8px;
    gap: 8px;
  }
  .product-card-img {
    width: 60px;
    height: 60px;
  }
  .product-card-name { font-size: 12px; }
  .product-card-price { font-size: 15px; }
  .product-card-desc,
  .product-card-sales,
  .product-card-original { display: none; }
  /* 聊天头部紧凑 */
  .chat-header {
    padding: 8px 12px;
  }
  .avatar {
    width: 34px;
    height: 34px;
  }
  .avatar img {
    width: 34px;
    height: 34px;
  }
  .chat-header-info h3 { font-size: 13px; }
  .chat-header-status { font-size: 11px; }
  /* 语言选择器移动端紧凑 */
  .lang-btn {
    padding: 4px 6px;
    font-size: 11px;
  }
  .lang-dropdown {
    right: -10px;
    min-width: 170px;
    max-height: 220px;
  }
  .lang-option {
    padding: 7px 10px;
    font-size: 12px;
  }
  .header-btn {
    padding: 4px 8px;
    font-size: 12px;
  }
  /* 消息区域紧凑 */
  .chat-messages {
    padding: 10px 12px;
    gap: 8px;
  }
  .msg-bubble { font-size: 13px; }
  .msg-bubble img { max-width: 100px; }
  /* 输入区紧凑 */
  .chat-input-area {
    padding: 8px 12px 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
  }
  .chat-input {
    padding: 10px 14px;
    font-size: 14px;
  }
  .send-btn {
    width: 40px;
    height: 40px;
  }
  .input-hint { display: none; }
  /* 消息最大宽度放宽 */
  .msg-row { max-width: 90%; }
}
