#rustrade-chat-root{
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1080;
  width: 64px;
  height: 64px;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  touch-action: none;
}

#rustrade-chat-btn{
  position: relative;
  display: block;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  cursor: grab;
  color: transparent;
  background: transparent;
  box-shadow: 0 8px 22px rgba(0,0,0,.18);
  overflow: visible;
  line-height: 0;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#rustrade-chat-btn:active{
  cursor: grabbing;
}

#rustrade-chat-btn img{
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 14px;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

#rustrade-chat-unread{
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #dc3545;
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  font-weight: 700;
  display: none;
  z-index: 1;
}

@media (max-width: 640px){
  #rustrade-chat-root:not(.rtc-pos-custom){
    bottom: 88px;
    right: 12px;
  }
}

#rustrade-chat-panel{
  /* 相对悬浮按钮向上展开，避免自定义 top 定位时面板向下撑出视口 */
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  display: none;
  width: 360px;
  max-width: calc(100vw - 36px);
  height: 460px;
  max-height: calc(100vh - 96px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0,0,0,.22);
  overflow: hidden;
  margin-bottom: 0;
  border: 1px solid rgba(0,0,0,.08);
  flex-direction: column;
}

#rustrade-chat-panel.open{ display: flex; }

#rustrade-chat-panel.has-sidebar{
  width: 680px;
  height: 520px;
}

#rustrade-chat-body{
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

#rustrade-chat-sidebar{
  display: none;
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid rgba(0,0,0,.08);
  background: #f7f7f8;
  flex-direction: column;
  min-height: 0;
}

#rustrade-chat-panel.has-sidebar #rustrade-chat-sidebar{
  display: flex;
}

.rtc-sidebar-head{
  padding: 12px 12px 10px;
  font-size: 13px;
  font-weight: 700;
  color: #222;
  border-bottom: 1px solid rgba(0,0,0,.06);
  flex-shrink: 0;
}

.rtc-threads-list{
  flex: 1;
  overflow: auto;
  padding: 4px 0;
}

.rtc-thread-item{
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-left: 3px solid transparent;
  border-bottom: 1px solid rgba(0,0,0,.04);
  background: transparent;
  padding: 10px 12px;
  cursor: pointer;
}

.rtc-thread-item:hover{
  background: rgba(230,45,4,.05);
}

.rtc-thread-item.is-active{
  background: #fff;
  border-left-color: var(--primary, #e62d04);
}

.rtc-thread-name{
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #222;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rtc-thread-unread{
  display: inline-block;
  margin-top: 4px;
  margin-right: 6px;
  min-width: 16px;
  padding: 0 5px;
  border-radius: 999px;
  background: #dc3545;
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  font-weight: 700;
  text-align: center;
}

.rtc-thread-meta{
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: rgba(0,0,0,.45);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#rustrade-chat-main{
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

#rustrade-chat-header{
  padding: 12px 12px;
  border-bottom: 1px solid rgba(0,0,0,.08);
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

#rustrade-chat-title-wrap{
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

#rustrade-chat-title{
  font-weight: 700;
  font-size: 14px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rtc-threads-btn{
  display: none;
  border: 1px solid rgba(0,0,0,.14);
  background: #fff;
  border-radius: 999px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: #555;
  flex-shrink: 0;
  white-space: nowrap;
}

#rustrade-chat-header-actions{
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.rtc-translate-btn{
  border: 1px solid rgba(0,0,0,.14);
  background: #fff;
  border-radius: 999px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: #555;
  line-height: 1.2;
  white-space: nowrap;
}

.rtc-translate-btn.is-on{
  background: #e8f5e9;
  border-color: #43a047;
  color: #2e7d32;
}

.rtc-tr-badge{
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #eef6ff;
  color: #1e66c6;
  font-size: 10px;
  font-weight: 600;
}

.msg.rtc-translating .rtc-msg-body{
  opacity: .55;
}

#rustrade-chat-close{
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

#rustrade-chat-log{
  flex: 1;
  overflow: auto;
  padding: 12px;
  font-size: 13px;
  color: #222;
  background: #fafafa;
  min-height: 0;
}

#rustrade-chat-footer{
  padding: 10px;
  border-top: 1px solid rgba(0,0,0,.08);
  display:flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  background: #fff;
}

#rustrade-chat-tools{
  display:flex;
  gap: 6px;
  width: 100%;
}

#rustrade-chat-attach,
#rustrade-chat-library,
.rtc-human-btn{
  border: 1px solid rgba(0,0,0,.12);
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}

#rustrade-chat-library-panel{
  display: none;
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 70px;
  max-height: 260px;
  background: #fff;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0,0,0,.16);
  z-index: 20;
  overflow: hidden;
  flex-direction: column;
}

#rustrade-chat-library-panel.open{
  display: flex;
}

.rtc-lib-head{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(0,0,0,.08);
  font-size: 13px;
  font-weight: 700;
}

.rtc-lib-list{
  flex: 1;
  overflow: auto;
  padding: 8px 10px;
}

.rtc-lib-item{
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 4px;
  font-size: 12px;
  border-bottom: 1px solid rgba(0,0,0,.04);
}

.rtc-lib-item label{
  flex: 1;
  cursor: pointer;
  margin: 0;
}

.rtc-lib-item .rtc-lib-meta{
  opacity: .6;
  font-size: 11px;
}

.rtc-lib-actions{
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid rgba(0,0,0,.08);
}

.rtc-lib-actions button{
  border: 1px solid rgba(0,0,0,.12);
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}

.rtc-lib-actions .rtc-lib-primary{
  background: var(--primary, #e62d04);
  border-color: transparent;
  color: #fff;
  flex: 1;
}

.rtc-lib-actions .rtc-lib-primary:disabled{
  opacity: .45;
  cursor: not-allowed;
}

.rtc-lib-del{
  border: 0;
  background: transparent;
  color: #c62828;
  cursor: pointer;
  font-size: 11px;
  padding: 0;
}


.rtc-file-hint,
.rtc-file-line{
  width: 100%;
  font-size: 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.rtc-file-hint{ opacity: .75; font-size: 11px; }

.rtc-ft-icon{
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
  border-radius: 5px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

.rtc-ft-badge{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 20px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .02em;
  color: #fff;
  line-height: 1;
  flex-shrink: 0;
  text-transform: uppercase;
}

.rtc-ft-pdf{ background: #e53935; }
.rtc-ft-word,.rtc-ft-doc{ background: #2b579a; }
.rtc-ft-excel,.rtc-ft-xls{ background: #217346; }
.rtc-ft-image,.rtc-ft-img{ background: #8e24aa; }
.rtc-ft-file{ background: #607d8b; }

.rtc-file-line a,
.rtc-file-line a.rtc-file-link{
  color: #e62d04;
  text-decoration: none;
  word-break: break-all;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.rtc-file-line a:hover{ text-decoration: underline; }
.rtc-file-line a .rtc-ft-icon,
.rtc-file-line a .rtc-file-name{ cursor: pointer; }

.rtc-lib-title{
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#rustrade-chat-input{
  flex: 1;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 10px;
  padding: 10px 10px;
  outline: none;
}

#rustrade-chat-send{
  border: 0;
  border-radius: 10px;
  padding: 0 14px;
  cursor: pointer;
  color: #fff;
  background: var(--primary, #e62d04);
}

.msg{
  margin: 0 0 10px 0;
  padding: 10px 10px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid rgba(0,0,0,.06);
  white-space: pre-wrap;
  max-width: 92%;
}

.msg.msg-row{
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 0;
  background: transparent;
  border: 0;
  max-width: 100%;
  white-space: normal;
}

.msg.msg-row .rtc-msg-bubble{
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid rgba(0,0,0,.06);
  white-space: pre-wrap;
  max-width: calc(100% - 44px);
  min-width: 0;
}

.msg.msg-row.msg-visitor{
  margin-left: auto;
  justify-content: flex-end;
  background: transparent;
  border: 0;
}

.msg.msg-row.msg-visitor .rtc-msg-bubble{
  background: #fff5f2;
  border-color: rgba(230,45,4,.12);
}

.msg.msg-row.msg-other{
  margin-right: auto;
  justify-content: flex-start;
  background: transparent;
  border: 0;
}

.rtc-msg-avatar{
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: #eee;
  border: 1px solid rgba(0,0,0,.06);
}

.msg .meta{
  font-size: 11px;
  opacity: .55;
  margin-bottom: 6px;
}

.rtc-sidebar-backdrop{
  display: none;
}

@media (max-width: 640px){
  #rustrade-chat-panel.has-sidebar{
    width: calc(100vw - 24px);
    height: min(560px, calc(100vh - 88px));
  }

  #rustrade-chat-panel.has-sidebar #rustrade-chat-sidebar{
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(260px, 78%);
    z-index: 25;
    box-shadow: 8px 0 24px rgba(0,0,0,.12);
    transform: translateX(-105%);
    transition: transform .2s ease;
  }

  #rustrade-chat-panel.has-sidebar.sidebar-open #rustrade-chat-sidebar{
    transform: translateX(0);
  }

  #rustrade-chat-panel.has-sidebar .rtc-threads-btn{
    display: inline-block;
  }

  #rustrade-chat-panel.has-sidebar .rtc-sidebar-backdrop{
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.28);
    z-index: 24;
    border: 0;
    padding: 0;
    cursor: pointer;
  }

  #rustrade-chat-panel.has-sidebar.sidebar-open .rtc-sidebar-backdrop{
    display: block;
  }
}
