:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #bf0000;
  --accent-soft: #fdecec;
  --blue: #1f6feb;
  --blue-soft: #e8f0fe;
  --green: #1a7f37;
  --green-soft: #e6f4ea;
  --amber: #9a6700;
  --amber-soft: #fff4d6;
  --red: #cf222e;
  --red-soft: #ffebe9;
  --merchant: #eef4ff;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 14px;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --text: #e6e8eb;
    --muted: #98a2b3;
    --line: #2a2f3a;
    --accent: #ff5c5c;
    --accent-soft: #3a1d1d;
    --blue: #6aa6ff;
    --blue-soft: #1a2740;
    --green: #4ac26b;
    --green-soft: #15301f;
    --amber: #e3b341;
    --amber-soft: #33290f;
    --red: #ff7b72;
    --red-soft: #3b1a1a;
    --merchant: #1a2233;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { filter: brightness(1.05); }
button.ghost { border-color: transparent; background: transparent; color: var(--blue); padding: 4px 8px; white-space: nowrap; }
button.danger { color: var(--red); }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; background: var(--panel); min-width: 0;
}
textarea { width: 100%; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field input, .field select, .field textarea { width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--line); color: var(--text); white-space: nowrap; }
.badge.red { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.notice { border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; line-height: 1.6; }
.notice.warn { background: var(--amber-soft); color: var(--amber); }
.notice.error { background: var(--red-soft); color: var(--red); }
.notice.ok { background: var(--green-soft); color: var(--green); }
.notice.info { background: var(--blue-soft); color: var(--blue); }

/* 顶部 */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 52px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--accent); white-space: nowrap; }
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--text); white-space: nowrap; }
.nav a.active { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.who { color: var(--muted); white-space: nowrap; font-size: 13px; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 16px; }
h1 { font-size: 18px; margin: 0 0 12px; }
h2 { font-size: 15px; margin: 0 0 10px; }

/* 登录 */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; }

/* 一览 */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button { border-radius: 999px; }
.tabs button.active { background: var(--text); color: var(--panel); border-color: var(--text); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input[type="search"] { flex: 1; min-width: 160px; }
.list-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--text); }
.list-item:hover { background: var(--bg); text-decoration: none; }
.list-item:last-child { border-bottom: none; }
.list-item .title { font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; min-width: 0; }
.list-item .preview { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; grid-column: 1 / 2; min-width: 0; }
.list-item .time { color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }
.list-item.awaiting { box-shadow: inset 3px 0 0 var(--accent); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 8px; justify-content: center; padding: 12px; }

/* 详情 */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.conversation { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.msg { max-width: 85%; border-radius: 10px; padding: 10px 12px; border: 1px solid var(--line); }
.msg.customer { align-self: flex-start; background: var(--panel); }
.msg.merchant { align-self: flex-end; background: var(--merchant); }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.msg .body { white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.msg.deleted .body { color: var(--muted); font-style: italic; }
.atts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.att { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; background: var(--panel); font-size: 12px; }
.att img { max-width: 160px; max-height: 120px; border-radius: 4px; display: block; }
.side dl, dl.side { margin: 0; display: grid; grid-template-columns: 72px 1fr; gap: 6px 8px; font-size: 13px; }
.side dt, dl.side dt { color: var(--muted); }
.side dd, dl.side dd { margin: 0; word-break: break-all; }
.composer { padding: 16px; border-top: 1px solid var(--line); }
.counter { font-size: 12px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; margin: 6px 0; }
.counter .bad { color: var(--red); font-weight: 600; }
.problems { margin: 6px 0; padding-left: 18px; color: var(--red); font-size: 13px; }
.outbox-item { border-left: 3px solid var(--line); padding: 6px 10px; margin: 6px 0; font-size: 13px; }
.outbox-item.unknown { border-color: var(--amber); background: var(--amber-soft); }
.outbox-item.failed { border-color: var(--red); }

/* 弹窗 */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 640px; max-height: 90vh; overflow: auto; }
.modal pre { white-space: pre-wrap; word-break: break-word; background: var(--bg); padding: 12px; border-radius: 6px; max-height: 40vh; overflow: auto; font-family: inherit; line-height: 1.7; }

/* 表格 */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.table-wrap { overflow-x: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }

#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--panel); padding: 8px 16px; border-radius: 6px; opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 60; max-width: calc(100% - 32px); }
#toast.show { opacity: 0.95; }

@media (max-width: 860px) {
  .detail { grid-template-columns: 1fr; }
  .msg { max-width: 95%; }
  .topbar { gap: 8px; }
  .who { display: none; }
}
