:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 14px;
  color: #182720;
  background: #f6f8f7;
  --line: #dce5e0;
  --muted: #556862;
  --accent: #106747;
  --soft: #e3f3eb;
  --error: #af292d;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100dvh; display: flex; flex-direction: column; }
h1, h2, p, dl { margin: 0; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, input, select, textarea { border: 1px solid #c5d2cd; border-radius: 5px; }
input, select, textarea { width: 100%; padding: 8px 10px; color: inherit; background: white; }
textarea { resize: vertical; }
button { background: white; color: inherit; padding: 7px 12px; cursor: pointer; }
button:hover:not(:disabled) { background: #edf3ef; }
button:disabled { cursor: not-allowed; opacity: .55; }
textarea:disabled { background: #f0f2f1; cursor: not-allowed; }
:focus-visible { outline: 2px solid #1f8762; outline-offset: 2px; }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: #084e34; }
button.quiet { background: transparent; border-color: transparent; }
label { display: grid; gap: 5px; }
.muted { color: var(--muted); }
.error { color: var(--error); overflow-wrap: anywhere; }
.page-error { padding: 7px 18px; background: #fff0f0; border-bottom: 1px solid #f0c7c7; }
.empty { color: var(--muted); padding: 20px; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.login-page { display: grid; place-items: center; padding: 20px; background: #eaf1ed; }
.login-panel { width: min(100%, 360px); border: 1px solid var(--line); border-top: 4px solid var(--accent); background: white; padding: 28px; }
.login-panel h1 { margin-bottom: 24px; }
form { display: grid; gap: 12px; }
.topbar { height: 54px; flex: 0 0 54px; display: flex; align-items: center; gap: 14px; padding: 0 20px; border-bottom: 1px solid var(--line); background: white; }
.brand { font-weight: 700; color: #17382a; white-space: nowrap; }
.topbar nav { display: flex; height: 100%; gap: 5px; margin-left: 10px; }
.topbar nav a { color: var(--muted); display: grid; align-items: center; padding: 0 12px; border-bottom: 2px solid transparent; white-space: nowrap; }
.topbar nav a[aria-current] { color: var(--accent); border-color: var(--accent); font-weight: 700; }
.account { margin-left: auto; color: var(--muted); text-align: right; }
.inbox { flex: 1; min-height: 0; display: grid; grid-template-columns: 260px minmax(260px,1fr) 280px; }
.threads, .chat, .customer { min-width: 0; min-height: 0; }
.threads { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: white; }
.thread-tools { padding: 13px 11px 9px; border-bottom: 1px solid var(--line); }
.thread-filter-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.filters { display: flex; flex: 1; gap: 4px; }
.filters button { flex: 1; border-color: transparent; padding-inline: 5px; white-space: nowrap; }
.workbench .filters.quality-filters {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
}
.workbench .filters.quality-filters button {
  min-width: 0; padding-inline: 2px; font-size: 12px;
  font-variant-numeric: tabular-nums; white-space: normal;
}
.thread-quality {
  display: inline-block; padding: 2px 6px; border-radius: 4px;
  font-size: 12px; line-height: 16px; font-weight: 600; white-space: nowrap;
}
.thread-tags .thread-quality { margin-inline-start: auto; }
.thread-quality[data-quality=high] { color: #166534; background: #dcfce7; }
.thread-quality[data-quality=low] { color: #374151; background: #e5e7eb; }
.thread-quality[data-quality=invalid] { color: #991b1b; background: #fee2e2; }
.thread-quality[data-quality=arrived] { color: #1e5a8a; background: #e6f1fb; }
.thread-quality[data-quality=undecided] { color: #525866; background: #f3f4f6; }
.lead-reminder-strip {
  margin: 0 0 8px; padding: 6px 8px; background: #f5f8f8;
  border-radius: 6px; color: var(--muted); font-size: 12px;
}
.lead-reminder-strip a { color: #0f766e; text-underline-offset: 2px; }
.unread-total { color: var(--error); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.filters button[aria-pressed=true], .categories button[aria-pressed=true] { background: var(--soft); color: var(--accent); font-weight: 700; }
.thread-list { overflow: auto; }
.thread { display: grid; width: 100%; grid-template-columns: minmax(0,1fr) auto; gap: 3px 7px; text-align: left; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); border-left: 3px solid transparent; border-radius: 0; }
.thread[aria-current=true] { background: var(--soft); border-left-color: #8495a4; }
.thread-title, .thread-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-phone, .thread time { color: var(--muted); font-size: 12px; }
.thread-phone { grid-column: 1 / -1; }
.thread-preview { color: var(--muted); font-size: 13px; }
.unread { color: white; background: #bb3b3f; min-width: 17px; padding: 1px 4px; border-radius: 12px; text-align: center; font-size: 11px; align-self: center; }
.chat { display: flex; flex-direction: column; }
.chat-empty { margin: auto; }
.chat-header { background: white; padding: 11px 16px 9px; border-bottom: 1px solid var(--line); }
.chat-header h1 { display: inline-block; margin-right: 8px; font-size: 17px; }
.window { margin-top: 7px; padding: 5px 8px; background: var(--soft); color: #1b6247; border-radius: 4px; font-size: 12px; font-variant-numeric: tabular-nums; }
.window.soon { color: #914608; background: #fff0d8; }
.window.closed { color: #455451; background: #e8ecea; }
#reply-window.closed { color: #a34700; background: #fff7e6; box-shadow: inset 0 0 0 1px #ffd591; }
.window.region-block { color: #932026; background: #fff0ef; box-shadow: inset 0 0 0 1px #f1bbb9; }
.chat-summary { padding: 4px 16px; color: var(--muted); font-size: 12px; }
.chat-summary details { display: inline; }
.chat-summary summary { display: inline; cursor: pointer; color: var(--accent); text-decoration: underline; }
.chat-summary p { margin: 4px 0 0; white-space: pre-wrap; }
.earlier-messages { text-align: center; padding: 4px; }
.earlier-messages button { font-size: 12px; }
.message-segment { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 0; }
.messages { display: flex; flex-direction: column; gap: 10px; overflow: auto; flex: 1; padding: 15px 16px; }
.message-date { display: flex; align-items: center; justify-content: center; gap: 9px; color: var(--muted); font-size: 12px; }
.message-date::before, .message-date::after { content: ""; width: 32px; height: 1px; background: var(--line); }
.message { max-width: min(82%, 640px); align-self: flex-start; }
.message.out { align-self: flex-end; }
.bubble { padding: 8px 11px; border-radius: 5px; background: #e9eeeb; overflow-wrap: anywhere; white-space: pre-wrap; }
.out .bubble { background: #d9f1e4; }
.message-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; margin: 3px 2px 0; font-size: 12px; color: var(--muted); }
.out .message-meta { justify-content: flex-end; }

.message-translate-button { min-height: 24px; padding: 0 6px; font-size: 12px; }
.message-translation { margin: 4px 2px 0; color: var(--muted); font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.translation-tools { display: flex; align-items: center; justify-content: flex-start; gap: 12px; }
.send-english-toggle { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.send-english-toggle input { accent-color: var(--accent); }
#send-english-notice { margin: 0; font-size: 12px; }
.translation-tools button { padding: 2px 8px; font-size: 12px; }
.translation-panel { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 5px; }
.translation-panel header, .translation-actions { display: flex; align-items: center; gap: 8px; }
.translation-panel header { justify-content: space-between; }
.translation-panel button { padding: 3px 8px; }
.translation-result { max-height: 8rem; overflow: auto; margin: 0; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }

.composer { background: white; border-top: 1px solid var(--line); padding: 10px 16px; gap: 7px; }
.composer textarea { max-height: 34vh; }
.composer-actions { display: flex; justify-content: flex-end; align-items: center; gap: 9px; }
.composer-actions #pick-reply { margin-right: auto; }
.composer-actions button:disabled {
  background: #e9eceb; border-color: #d3dad6; color: #5d6963; opacity: 1;
}
.shortcut { font-size: 12px; }
.customer { background: white; border-left: 1px solid var(--line); padding: 14px; overflow: auto; }
.customer dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 8px; margin: 12px 0; font-size: 13px; }
.customer dd { margin: 0; overflow-wrap: anywhere; }
.customer dt { color: var(--muted); }
.customer form { margin-top: 10px; gap: 8px; }
.customer form button { justify-self: end; }
.lead-status { color: var(--accent); font-weight: 700; padding: 7px 0; }
dialog { width: min(500px, 94vw); max-height: 82vh; padding: 15px; color: inherit; border: 1px solid var(--line); border-radius: 6px; }
dialog::backdrop { background: #152a2080; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.reply-options { display: grid; gap: 6px; margin-top: 10px; }
.reply-option { text-align: left; display: grid; gap: 4px; overflow-wrap: anywhere; }
.library { display: grid; grid-template-columns: 210px minmax(0, 1fr); flex: 1; min-height: 0; }
.library-sidebar { background: white; border-right: 1px solid var(--line); padding: 15px 12px; overflow: auto; }
.categories { display: grid; gap: 4px; margin-top: 10px; }
.categories button { border-color: transparent; text-align: left; overflow-wrap: anywhere; }
.library-main { padding: 16px; overflow: auto; }
.library-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.library-tools h1 { margin-right: auto; white-space: nowrap; }
.library-tools input { max-width: 240px; }
.library-tools button { white-space: nowrap; }
.table-scroll { overflow: auto; }
table { width: 100%; min-width: 480px; border-collapse: collapse; background: white; }
th, td { padding: 9px 11px; text-align: left; border: 1px solid var(--line); }
th { background: #ecf3ef; font-weight: 650; }
td.count, td.actions { width: 1%; white-space: nowrap; }
td.actions button + button { margin-left: 5px; }
td.preview { max-width: 0; width: 58%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 850px) {
  .inbox { grid-template-columns: 205px minmax(240px,1fr) 225px; overflow: auto; }
  .topbar { padding: 0 9px; gap: 5px; }
  .topbar nav { margin: 0; }
  .topbar nav a { padding: 0 7px; }
  .library { grid-template-columns: minmax(100px, 23%) minmax(0,1fr); }
}

/* 会话台 */
.presence { margin-bottom: 10px; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.presence-controls { display: flex; align-items: center; gap: 6px; }
.presence-controls label, .presence-controls button { white-space: nowrap; }
.presence-controls select { width: auto; min-width: 0; padding: 5px 3px; }
.presence-controls button { padding: 5px 7px; color: var(--accent); }
.presence p { margin-top: 4px; font-size: 12px; }
.availability-note { color: var(--accent); }
.thread-section-title {
  padding: 6px 12px; border-bottom: 1px solid var(--line);
  background: #f5f8f6; color: var(--muted); font-size: 12px; font-weight: 700;
}
.thread[data-mine=true] { border-left-color: #3973bd; }
.thread[data-priority=overdue] .thread-reply { color: var(--error); font-weight: 650; }
.thread[data-priority=urgent] { background: #fff0ef; }
.thread[data-priority=urgent]:hover, .thread[data-priority=urgent][aria-current=true] { background: #fbe1df; }
.thread[data-priority=urgent] .thread-title, .thread[data-priority=urgent] .thread-reply {
  color: #932026; font-weight: 700;
}
.thread-phone { grid-column: 1; }
.thread-owner {
  max-width: 100px; color: var(--muted); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right;
}
.thread-reply, .thread-assist { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.thread-assist { color: var(--accent); overflow-wrap: anywhere; }
#more-threads, #more-closed { display: block; margin: 9px auto; }
#closed-title { cursor: pointer; }
#closed-title:hover { background: #eaf0ed; }
.chat-heading { display: flex; align-items: center; gap: 9px; }
.chat-identity { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.chat-title { display: inline-flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; margin-right: 8px; }
.chat-title h1 { margin-right: 0; }
.chat-assisted {
  background: var(--soft); color: #185d47; padding: 2px 6px; border-radius: 4px; font-size: 12px;
}
.chat-owner { margin-left: 8px; font-size: 12px; color: var(--muted); }
.chat-image { display: block; max-width: 100%; max-height: min(360px, 60dvh); object-fit: contain; }
.message-operator { color: var(--accent); font-weight: 650; }
.draft-image { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.draft-image span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-image button { flex: none; }
.inbox-page .composer textarea { max-height: 34dvh; }
.mobile-control { display: none; }

@media (max-width: 768px) {
  .inbox-page .topbar .account { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .inbox-page .topbar a, .inbox-page .topbar button, .inbox-page .inbox button,
  .inbox-page .inbox select, #customer-drawer button { min-height: 44px; }
  #closed-title { min-height: 44px; padding-block: 13px; }
  .inbox-page .topbar { gap: 3px; }
  .inbox-page .topbar nav a { padding-inline: 5px; }
  .inbox-page .topbar button { padding-inline: 7px; }
  .inbox-page .inbox { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); overflow: hidden; }
  .inbox[data-view=list] > .chat, .inbox[data-view=chat] > .threads,
  .inbox > .customer { display: none; }
  .inbox > .threads { border-right: 0; }
  .inbox .mobile-control { display: block; padding-inline: 8px; flex: none; }
  .inbox .chat-header { padding: 7px 9px; }
  .inbox .chat-title { display: flex; margin-right: 0; }
  .inbox .chat-header h1 { margin: 0; font-size: 15px; }
  .inbox .chat-owner { display: block; margin: 0; }
  .inbox .chat-identity .muted { font-size: 12px; }
  .inbox .messages { padding: 10px; }
  .inbox .composer {
    padding: 7px 9px calc(7px + env(safe-area-inset-bottom));
  }
  .inbox .composer textarea { font-size: 16px; }
  .inbox .shortcut { display: none; }
  #customer-drawer {
    inset: auto 0 0; margin: 0; width: 100%; max-width: none; max-height: 85dvh;
    border-radius: 10px 10px 0 0; padding: 0 0 env(safe-area-inset-bottom);
  }
  #customer-drawer .dialog-header { padding: 5px 14px; border-bottom: 1px solid var(--line); margin: 0; }
  #customer-drawer .customer { border: 0; overflow: visible; }
  #customer-drawer .customer > h2 { display: none; }
}

@keyframes customer-drawer-enter {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
  #customer-drawer[open] { animation: customer-drawer-enter 160ms ease-out; }
}
