/**
 * =====================================================
 * 聊天系统 V2 — 功能基础样式
 * 
 * 🎨 UI设计师注意：
 *   此文件仅包含功能所必需的最小样式（布局框架）。
 *   您可以完全重写此文件中的任何规则 — 只要保留:
 *   1) 所有选择器名称（CSS类名和元素ID不变）
 *   2) display:none/block 的切换逻辑（由 JS 控制）
 *   3) position 相关属性（影响布局流）
 * 
 *   建议设计要点：
 *   - 深色科技风推荐色：背景 #080c14, 主色 #00d4ff, 辅色 #8b5cf6
 *   - 消息气泡：自己右对齐(蓝/青)、对方左对齐(灰色)
 *   - 圆角：统一 8-16px
 *   - 输入区：底部固定，适配移动端安全区
 * =====================================================
 */

/* ---- 布局框架 ---- */
.chatv2-layout {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* ---- 左侧侧边栏 ---- */
.chatv2-sidebar {
  width: 320px;
  min-width: 280px;
  border-right: 1px solid var(--border-color, #e5e7eb);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chatv2-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.chatv2-sidebar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
}

.chatv2-sidebar-icon {
  font-size: 18px;
}

.chatv2-new-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- 搜索框 ---- */
.chatv2-search-box {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  gap: 8px;
}

.chatv2-search-icon {
  font-size: 14px;
  opacity: 0.5;
  flex-shrink: 0;
}

.chatv2-search-box input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  background: transparent;
  min-width: 0;
}

/* ---- 对话列表 ---- */
.chatv2-conv-list {
  flex: 1;
  overflow-y: auto;
  /* 自定义滚动条 */
  scrollbar-width: thin;
}

.chatv2-conv-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  transition: background 0.15s;
}

.chatv2-conv-item:hover {
  background: rgba(0,0,0,0.03);
}

.chatv2-conv-item.active {
  background: rgba(59, 130, 246, 0.08);
  border-left: 3px solid #3b82f6;
}

.chatv2-conv-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.chatv2-conv-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.chatv2-conv-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.chatv2-conv-name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chatv2-conv-role {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(59,130,246,0.1);
  color: #3b82f6;
  flex-shrink: 0;
}

.chatv2-conv-time {
  font-size: 12px;
  opacity: 0.5;
  flex-shrink: 0;
}

.chatv2-conv-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

.chatv2-conv-preview {
  font-size: 13px;
  opacity: 0.6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chatv2-unread-dot {
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

/* ---- 管理员分组 ---- */
.chatv2-admin-group {
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

.chatv2-admin-group-title {
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  opacity: 0.5;
  letter-spacing: 0.5px;
  background: rgba(0,0,0,0.02);
}

.chatv2-admin-group .chatv2-conv-item {
  padding-left: 24px;
}

/* ---- 空状态 ---- */
.chatv2-empty-list {
  text-align: center;
  padding: 40px 20px;
  font-size: 14px;
  opacity: 0.5;
}

/* ---- 右侧主区域 ---- */
.chatv2-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.chatv2-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.chatv2-empty-icon {
  font-size: 48px;
  opacity: 0.3;
}

.chatv2-empty-title {
  font-size: 18px;
  font-weight: 500;
}

.chatv2-empty-desc {
  font-size: 14px;
  opacity: 0.5;
}

.chatv2-empty-btn {
  margin-top: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: 10px;
  background: #3b82f6;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

/* ---- 对话详情 ---- */
.chatv2-chat-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---- 头部 ---- */
.chatv2-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  gap: 12px;
  flex-shrink: 0;
}

.chatv2-back-btn {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  display: none; /* 桌面端隐藏，移动端显示 */
}

.chatv2-header-info {
  flex: 1;
  min-width: 0;
}

.chatv2-header-title {
  font-size: 15px;
  font-weight: 600;
}

.chatv2-header-sub {
  font-size: 12px;
  opacity: 0.5;
}

.chatv2-readonly-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.chatv2-clear-btn {
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.chatv2-clear-btn:hover {
  opacity: 1;
}

/* ---- 消息列表 ---- */
.chatv2-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: thin;
}

/* ---- 消息 ---- */
.chatv2-msg {
  display: flex;
  gap: 8px;
  max-width: 80%;
  margin-bottom: 12px;
}

.chatv2-msg-self {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chatv2-msg-other {
  align-self: flex-start;
}

.chatv2-msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.chatv2-msg-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chatv2-msg-sender {
  font-size: 12px;
  opacity: 0.6;
  margin-bottom: 2px;
}

.chatv2-msg-body {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.chatv2-msg-self .chatv2-msg-body {
  background: #3b82f6;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chatv2-msg-other .chatv2-msg-body {
  background: #f3f4f6;
  color: #1f2937;
  border-bottom-left-radius: 4px;
}

.chatv2-msg-image {
  border-radius: 12px;
  overflow: hidden;
  max-width: 260px;
}

.chatv2-msg-image img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
}

.chatv2-msg-time {
  font-size: 11px;
  opacity: 0.5;
  text-align: right;
}

.chatv2-msg-self .chatv2-msg-time {
  text-align: right;
}

.chatv2-msg-other .chatv2-msg-time {
  text-align: left;
}

/* ---- 时间分割线 ---- */
.chatv2-msg-time-divider {
  text-align: center;
  margin: 16px 0;
}

.chatv2-msg-time-divider span {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 100px;
  background: rgba(0,0,0,0.06);
  color: #6b7280;
}

/* ---- 临时/失败消息状态 ---- */
.chatv2-msg-temp .chatv2-msg-body {
  opacity: 0.7;
}

.chatv2-msg-sending {
  color: #9ca3af !important;
  font-style: italic;
}

.chatv2-msg-failed .chatv2-msg-body {
  background: #fee2e2 !important;
  color: #991b1b !important;
  border: 1px dashed #f87171;
}

.chatv2-msg-failed .chatv2-msg-sending {
  color: #ef4444 !important;
}

/* ---- 输入区 ---- */
.chatv2-composer {
  display: flex;
  align-items: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border-color, #e5e7eb);
  gap: 8px;
  flex-shrink: 0;
}

.chatv2-composer-tools {
  display: flex;
  gap: 4px;
  align-items: center;
}

.chatv2-tool-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  transition: opacity 0.15s, background 0.15s;
}

.chatv2-tool-btn:hover {
  opacity: 1;
  background: rgba(0,0,0,0.05);
}

/* 附件弹出菜单 */
.chatv2-attach-btn {
  opacity: 1;
  background: rgba(24,144,255,0.08);
  color: #1890ff;
}
.chatv2-attach-btn:hover {
  background: rgba(24,144,255,0.15);
}

/* 附件弹出菜单 - 紧贴按钮的小浮层 */
.chatv2-attach-menu {
  position: absolute;
  z-index: 9999;
  display: none;
  transform-origin: bottom left;
}

.chatv2-attach-popup {
  background: #fff;
  border-radius: 12px;
  padding: 6px;
  width: 168px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.16), 0 0 0 1px rgba(0,0,0,0.04);
  pointer-events: auto;
  animation: popIn 0.15s ease;
}

@keyframes popIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* 移动端适配 */
@media (max-width: 768px) {
  .chatv2-attach-popup {
    width: 150px;
    padding: 4px;
  }
}

.chatv2-attach-popup-title {
  display: none;
}

.chatv2-attach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 2px;
}
.chatv2-attach-item:last-child {
  margin-bottom: 0;
}
.chatv2-attach-item:hover {
  background: #f0f5ff;
}
.chatv2-attach-item:active {
  background: #e6f3ff;
}

.chatv2-attach-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chatv2-attach-label {
  font-size: 13px;
  color: #1f2937;
  font-weight: 500;
}

.chatv2-attach-btn.active {
  background: rgba(24,144,255,0.2);
  transform: rotate(45deg);
  transition: transform 0.2s;
}

.chatv2-composer textarea {
  flex: 1;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 120px;
  font-family: inherit;
  background: transparent;
}

.chatv2-composer textarea:focus {
  border-color: #3b82f6;
}

.chatv2-send-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 10px;
  background: #3b82f6;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.chatv2-send-btn:hover {
  background: #2563eb;
}

.chatv2-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- 未读徽标（侧边栏内部） ---- */
#chatV2UnreadBadge {
  font-size: 10px;
  background: #ef4444;
  color: #fff;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 6px;
}

/* ---- 移动端适配 ---- */
@media (max-width: 768px) {
  .chatv2-layout {
    position: relative;
  }
  
  .chatv2-sidebar {
    width: 100%;
    min-width: 0;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 10;
    background: #fff;
    transition: transform 0.25s ease;
  }
  
  .chatv2-sidebar.chatv2-sidebar-hidden-mobile {
    display: none;
  }
  
  .chatv2-main {
    width: 100%;
    flex: 1;
    position: relative;
    z-index: 1;
  }
  
  .chatv2-back-btn {
    display: block; /* 移动端显示返回按钮 */
  }
  
  .chatv2-msg {
    max-width: 90%;
  }
  
  .chatv2-composer {
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

/* ---- 卡片消息（工单/车辆） ---- */
.chatv2-card-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(59, 130, 246, 0.25);
  background: #fff;
  cursor: pointer;
  min-width: 240px;
  max-width: 300px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s, box-shadow 0.15s;
}

.chatv2-card-msg:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.chatv2-msg-self .chatv2-card-msg {
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.95);
}

.chatv2-card-order {
  border-left: 4px solid #3b82f6;
}

.chatv2-card-vehicle {
  border-left: 4px solid #10b981;
}

.chatv2-card-icon {
  font-size: 22px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #f3f4f6;
  border-radius: 8px;
}

.chatv2-card-body {
  flex: 1;
  min-width: 0;
}

.chatv2-card-title {
  font-weight: 600;
  font-size: 14px;
  color: #1f2937;
  margin-bottom: 4px;
}

.chatv2-card-desc {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.4;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chatv2-card-hint {
  font-size: 11px;
  color: #3b82f6;
  margin-top: 4px;
  font-weight: 500;
}

.chatv2-msg-self .chatv2-card-title,
.chatv2-msg-self .chatv2-card-desc {
  color: #1f2937;
}

.chatv2-msg-self .chatv2-card-hint {
  color: #2563eb;
}
