/* 工单页：页头（标题 + 新建）+ 列表卡；对话抽屉用页面底，我方陶土气泡配深色字，客服白底气泡 */
.ticket-list { padding: 12px var(--card-pad) var(--card-pad); min-height: 160px; }

.ticket-unread-badge {
  margin-left: 8px;
}
/* 独立徽标（非包裹）：行内居中 */
.ticket-unread-badge.tt-badge-count {
  vertical-align: middle;
  background: var(--primary);
  color: var(--text-1);
  box-shadow: none;
}
.subject-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: var(--t-body-strong);
}
.reply-tag {
  margin: 0;
}
.ticket-id {
  font: var(--t-caption);
  font-family: var(--font-mono);
}
.ticket-date {
  font: var(--t-caption);
  font-variant-numeric: tabular-nums;
}
.tc-unread-dot {
  margin-right: 7px;
  vertical-align: middle;
}

/* ---------- 状态标签：沿用 tt-tag 的圆角 6 与浅底配色，前面加一颗色点 ---------- */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.status-pill .pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

/* ---------- 工单对话 ---------- */
.chat {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}
.chat-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.chat-row.me {
  align-items: flex-end;
}
/* 气泡：靠发言一侧的下角收成 4；我方陶土底 + 深色字（陶土上不用白字），客服白底托一层 e1 */
.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-xs);
  background: var(--bg-card);
  box-shadow: var(--shadow-e1);
  font: var(--t-body);
  color: var(--text-1);
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-row.me .bubble {
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-xs) var(--radius-lg);
  background: var(--primary);
  box-shadow: none;
  color: var(--text-1);
}
.time {
  margin-top: 4px;
  font: var(--t-caption);
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
}
.reply {
  position: sticky;
  bottom: 0;
  z-index: 1;
  flex: none;
  margin: auto -24px 0;
  padding: 12px 24px 16px;
  background: var(--bg-card);
  box-shadow: inset 0 var(--hairline) 0 var(--border);
}
/* 回复输入栏：桌面端输入框整行，下方「附件 + 回复」；手机端单行「附件 / 输入框 / 回复」 */
.reply-compose {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "text text"
    "attach send";
  gap: 10px;
}
.reply-compose .tt-textarea { grid-area: text; }
.reply-compose .reply-btn { grid-area: send; }
.reply-attach-btn {
  grid-area: attach;
  font-size: var(--icon-18);
  color: var(--text-1);
}

/* ---------- 附件：新建工单 / 回复的待发送列表 ---------- */
.ticket-attach { position: relative; }
.ticket-attach-hint { margin-top: 8px; }
.ticket-attach-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  opacity: 0;
  pointer-events: none;
}
.ticket-attach-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.ticket-attach-list[hidden] { display: none; }
.reply-attach-list {
  margin: 0 0 10px;
  max-height: 168px;
  overflow-y: auto;
}
.ticket-attach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px;
  border-radius: var(--radius-inner);
  background: var(--bg-sunken);
}
.ticket-attach-item.is-error {
  background: var(--danger-soft);
  box-shadow: inset 0 0 0 1.5px var(--danger);
}
.ticket-attach-thumb {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-3);
  font-size: var(--icon-20);
}
.ticket-attach-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ticket-attach-item.is-done .ticket-attach-thumb { color: var(--primary); background: var(--primary-soft); }
.ticket-attach-item.is-error .ticket-attach-thumb { color: var(--danger-text); background: var(--bg-card); }
.ticket-attach-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ticket-attach-name {
  overflow: hidden;
  font: var(--t-body-strong);
  color: var(--text-1);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ticket-attach-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font: var(--t-caption);
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
}
.ticket-attach-meta .tt-spinner-sm { width: 12px; height: 12px; flex: none; }
.ticket-attach-item.is-error .ticket-attach-meta { color: var(--danger-text); }
.ticket-attach-remove {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  font-size: var(--icon-14);
  cursor: pointer;
  transition: transform var(--dur-fast) ease-out, color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.ticket-attach-remove:hover { color: var(--text-1); background: var(--hover-overlay); }
.ticket-attach-remove:active { transform: scale(0.98); }
.ticket-attach-remove:focus-visible { outline: 1.5px solid var(--primary); outline-offset: 2px; }

/* ---------- 对话里的附件：图片缩略图 / 文件卡 ---------- */
.chat-attachments {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: 80%;
  margin-top: 6px;
}
.chat-attachments:first-child { margin-top: 0; }
.chat-row.me .chat-attachments { align-items: flex-end; }
.chat-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat-row.me .chat-images { justify-content: flex-end; }
.chat-image {
  display: block;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--bg-sunken);
  box-shadow: var(--shadow-e1);
  line-height: 0;
}
.chat-image img {
  display: block;
  width: auto;
  height: auto;
  min-width: 48px;
  min-height: 48px;
  max-width: 180px;
  max-height: 180px;
  object-fit: cover;
}
.chat-file {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 240px;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-inner);
  background: var(--bg-card);
  box-shadow: var(--shadow-e1);
  color: var(--text-1);
  text-decoration: none;
  transition: box-shadow var(--dur) var(--ease);
}
@media (hover: hover) {
  .chat-file:hover { box-shadow: var(--shadow-e2); }
}
.chat-file:hover,
.chat-file:focus-visible { color: var(--text-1); text-decoration: none; }
.chat-file-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: var(--icon-20);
}
.chat-file-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-file-name {
  overflow: hidden;
  font: var(--t-body-strong);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-file-size { font: var(--t-caption); font-variant-numeric: tabular-nums; color: var(--text-3); }
.chat-file-action { flex: none; color: var(--text-3); font-size: var(--icon-16); }
.chat-file:hover .chat-file-action { color: var(--primary); }

/* ---------- 移动端卡片 ---------- */
.ticket-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ticket-card {
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-e1);
  cursor: pointer;
  transition: transform var(--dur-fast) ease-out, box-shadow var(--dur) var(--ease);
}
.ticket-card:active { transform: scale(0.98); }
@media (hover: hover) {
  .ticket-card:hover { box-shadow: var(--shadow-e2); }
}
.tc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 0;
  box-shadow: inset 0 calc(var(--hairline) * -1) 0 var(--border);
}
.tc-subject {
  font: var(--t-title);
  color: var(--text-1);
  word-break: break-all;
}
.tc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}
.tc-label {
  font: var(--t-caption);
  color: var(--text-3);
  flex-shrink: 0;
}
.tc-value {
  font: var(--t-caption);
  text-align: right;
  color: var(--text-2);
}

/* ---------- 表格 / 抽屉（宽度沿用 tt-drawer 的 520） ---------- */
.ticket-table {
  min-width: 720px;
}
/* 关闭按钮在标题左侧 */
.ticket-drawer .offcanvas-header {
  justify-content: flex-start;
  gap: 12px;
}
.ticket-drawer .offcanvas-header .btn-close {
  margin: 0;
}
/* 聊天底：浅灰，白色气泡靠阴影托起；回复栏白底贴底 */
.ticket-drawer .offcanvas-body {
  display: flex;
  flex-direction: column;
  padding: 24px 24px 0;
  background: var(--bg-page);
}

@media screen and (max-width: 768px) {
  .ticket-drawer.offcanvas-end {
    --bs-offcanvas-width: 100%;
  }
  /* 新建工单入口移到 App 顶栏右侧 */
  .ticket .tt-portal-head > .tt-btn { display: none; }

  /* 对话抽屉：高度跟随可视视口（iOS 键盘弹出时输入栏仍在屏内），输入栏吸底 */
  .ticket-drawer.offcanvas-end {
    bottom: auto;
    height: 100%;
    height: var(--vvh, 100%);
  }
  .ticket-drawer .offcanvas-body { padding: 16px 16px 0; }
  .chat { margin-bottom: 16px; }
  .bubble { max-width: 85%; }
  .chat-attachments { max-width: 85%; }
  .reply {
    margin: auto -16px 0;
    padding: 10px calc(16px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(16px + var(--safe-left));
  }
  .reply-compose {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "attach text send";
    align-items: end;
    gap: 8px;
  }
  .reply-attach-list { margin-bottom: 8px; max-height: 136px; }
  .reply .tt-textarea {
    min-width: 0;
    height: var(--input-h);
    min-height: var(--input-h);
    max-height: 120px;
    padding: 10px 12px;
    resize: none;
  }
  .reply .reply-btn { width: auto; }

  /* 列表：去掉外层卡片，工单项本身是白卡 */
  .ticket-list.tt-card { padding: 0; background: transparent; box-shadow: none; }
}

.ticket .tt-table-wrap { overflow-x: auto; }
#ticket-create-modal .modal-body { padding-top: 16px; }
