/* 客服中心 */

html, body { height: 100%; }
body { margin: 0; background: #f4f6f5; }
.sp-page {
  max-width: 640px; margin: 0 auto; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; background: #f4f6f5;
}

/* ---------- 头 ---------- */
.sp-header {
  flex: 0 0 auto; background: linear-gradient(160deg, #1f5c48, #2d6b58); color: #fff;
  padding: 10px 12px 0; position: relative;
}
.sp-back {
  position: absolute; left: 10px; top: 10px; width: 32px; height: 32px; line-height: 32px; text-align: center;
  color: #fff; text-decoration: none; font-size: 18px; border-radius: 50%; background: rgba(255,255,255,.14);
}
.sp-title { text-align: center; padding: 4px 40px 8px; }
.sp-title b { display: block; font-size: 16px; }
.sp-title span { display: block; font-size: 11px; opacity: .8; margin-top: 2px; }
.sp-tabs { display: flex; gap: 4px; }
.sp-tab {
  flex: 1; height: 38px; border: 0; background: transparent; color: rgba(255,255,255,.75);
  font-size: 14px; font-weight: 600; border-radius: 10px 10px 0 0; position: relative;
}
.sp-tab.active { background: #f4f6f5; color: #1f5c48; }
.sp-badge {
  display: inline-block; min-width: 16px; height: 16px; line-height: 16px; padding: 0 4px; border-radius: 8px;
  background: #e5533d; color: #fff; font-size: 10px; font-style: normal; text-align: center; vertical-align: 1px;
}
.sp-badge[hidden] { display: none; }

/* ---------- 面板 ---------- */
.sp-panel { flex: 1; min-height: 0; display: none; flex-direction: column; }
.sp-panel.active { display: flex; }
.sp-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px 24px; -webkit-overflow-scrolling: touch; }

/* ---------- 对话 ---------- */
.sp-chat { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px 8px; -webkit-overflow-scrolling: touch; }
.sp-msg { display: flex; margin-bottom: 10px; }
.sp-msg.user { justify-content: flex-end; }
.sp-msg.sys { justify-content: center; }
.sp-bubble {
  max-width: 82%; padding: 10px 13px; border-radius: 14px; font-size: 14.5px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.sp-msg.bot .sp-bubble, .sp-msg.staff .sp-bubble { background: #fff; color: #1f2d29; border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.sp-msg.staff .sp-bubble { border-left: 3px solid #2d6b58; }
.sp-msg.user .sp-bubble { background: #2d6b58; color: #fff; border-bottom-right-radius: 4px; }
.sp-msg.sys .sp-bubble { background: transparent; color: #98a4a0; font-size: 12px; padding: 4px 8px; text-align: center; }
.sp-msg.err .sp-bubble { background: #fff3f0; color: #8a3324; }
.sp-role { display: block; font-size: 11px; color: #98a4a0; margin: 0 0 3px 4px; }
.sp-time { display: block; font-size: 10.5px; color: #b0bab7; margin: 3px 4px 0; }
.sp-msg.user .sp-time { text-align: right; }
.sp-typing .sp-bubble { color: #98a4a0; letter-spacing: 3px; white-space: nowrap; word-break: keep-all; min-width: 40px; }

.sp-quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.sp-quick button {
  border: 1px solid #cfe0d8; background: #fff; color: #2d6b58; border-radius: 999px;
  padding: 7px 12px; font-size: 13px; text-align: left;
}

.sp-handoff {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0 12px 8px; padding: 9px 12px; border-radius: 10px;
  background: #fff6e3; border: 1px solid #f1dcae; color: #6b4a06; font-size: 13px;
}
.sp-handoff[hidden] { display: none; }

.sp-input {
  flex: 0 0 auto; display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid #e6ece9;
}
.sp-input textarea {
  flex: 1; resize: none; border: 1px solid #d6e0dc; border-radius: 12px; padding: 10px 12px;
  font-size: 15px; line-height: 1.4; max-height: 120px; background: #fafcfb; color: #1f2d29;
}
.sp-input textarea:focus { outline: none; border-color: #2d6b58; background: #fff; }
.sp-send {
  flex: 0 0 42px; height: 42px; border-radius: 50%; border: 0; background: #2d6b58; color: #fff;
  font-size: 20px; font-weight: 700;
}
.sp-send:disabled { background: #b4c4be; }

/* ---------- 按钮 ---------- */
.sp-btn {
  display: inline-flex; align-items: center; justify-content: center; height: 42px; padding: 0 18px;
  border-radius: 10px; border: 1px solid #c5d4ce; background: #fff; color: #2d6b58;
  font-size: 14.5px; font-weight: 700; text-decoration: none; cursor: pointer;
}
.sp-btn-primary { background: #2d6b58; color: #fff; border-color: #2d6b58; }
.sp-btn-sm { height: 32px; padding: 0 14px; font-size: 13px; }
.sp-btn:disabled { opacity: .6; }

/* ---------- 工单 ---------- */
.sp-login-tip { text-align: center; padding: 40px 20px; color: #556360; font-size: 14px; }
.sp-login-tip p { margin: 0 0 16px; }
.sp-ticket-list { display: grid; gap: 8px; }
.sp-ticket {
  background: #fff; border-radius: 12px; padding: 12px 14px; box-shadow: 0 1px 3px rgba(0,0,0,.05);
  display: grid; grid-template-columns: 1fr auto; row-gap: 4px; cursor: pointer;
}
.sp-ticket b { font-size: 14.5px; color: #1f2d29; }
.sp-ticket .sp-tk-status { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; align-self: start; }
.sp-tk-status.waiting_staff { background: #fff6e3; color: #a66a00; }
.sp-tk-status.replied { background: #e8f5ee; color: #245a49; }
.sp-tk-status.closed { background: #eef1f0; color: #7a8884; }
.sp-tk-status.open { background: #eef1f0; color: #7a8884; }
.sp-ticket small { grid-column: 1 / -1; font-size: 12.5px; color: #7a8884; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-ticket .sp-tk-time { grid-column: 1 / -1; font-size: 11px; color: #b0bab7; }
.sp-ticket.unread b::after { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #e5533d; margin-left: 6px; vertical-align: 2px; }
.sp-empty { text-align: center; color: #98a4a0; font-size: 13px; padding: 30px 0 10px; }
.sp-newticket { width: 100%; margin-top: 12px; height: 46px; }

.sp-ticket-detail { display: flex; flex-direction: column; height: 100%; margin: -14px -12px -24px; }
.sp-ticket-detail[hidden] { display: none; }
.sp-td-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 0; }
.sp-td-back { border: 0; background: transparent; color: #2d6b58; font-size: 14px; font-weight: 600; padding: 4px 0; }
.sp-ticket-detail h3 { margin: 6px 12px 4px; font-size: 15px; color: #1f2d29; }
.sp-chat-ticket { flex: 1; }

/* ---------- 联系方式 ---------- */
.sp-contact-lead { margin: 0 0 12px; font-size: 13px; color: #556360; line-height: 1.6; }
.sp-card {
  background: #fff; border-radius: 12px; padding: 14px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.05);
  display: flex; align-items: center; gap: 12px;
}
.sp-card-ico { font-size: 24px; flex: 0 0 auto; }
.sp-card-body { flex: 1; min-width: 0; }
.sp-card-body b { display: block; font-size: 14.5px; color: #1f2d29; }
.sp-card-body small { display: block; font-size: 12px; color: #7a8884; margin-top: 2px; line-height: 1.5; }
.sp-card .sp-btn { flex: 0 0 auto; height: 34px; padding: 0 14px; font-size: 13px; }
.sp-card img { width: 140px; height: 140px; border-radius: 8px; }
.sp-contact-faq { margin-top: 18px; background: #fff; border-radius: 12px; padding: 12px 14px; }
.sp-contact-faq b { display: block; font-size: 13px; color: #7a8884; margin-bottom: 8px; }
.sp-contact-faq a { display: inline-block; margin: 0 10px 8px 0; color: #2d6b58; font-size: 14px; text-decoration: none; }

/* ---------- 弹层 ---------- */
.sp-modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sp-modal[hidden] { display: none; }
.sp-modal-card { width: 100%; max-width: 640px; background: #fff; border-radius: 16px 16px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }
.sp-modal-card h3 { margin: 0 0 6px; font-size: 17px; }
.sp-modal-tip { margin: 0 0 10px; font-size: 12.5px; color: #7a8884; line-height: 1.6; }
.sp-modal-card textarea { width: 100%; box-sizing: border-box; border: 1px solid #d6e0dc; border-radius: 10px; padding: 10px 12px; font-size: 14.5px; line-height: 1.5; resize: vertical; }
.sp-modal-attach { display: flex; align-items: center; gap: 6px; margin: 10px 0 14px; font-size: 13px; color: #556360; }
.sp-modal-actions { display: flex; gap: 10px; }
.sp-modal-actions .sp-btn { flex: 1; }

.sp-toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(10px);
  background: rgba(31,45,41,.92); color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; opacity: 0; transition: .25s; z-index: 999; max-width: 86vw; text-align: center;
}
.sp-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.sp-toast.err { background: rgba(160,50,40,.95); }
