:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --subtle: #f8fafc;
  --border: #ebedf0;
  --border-strong: #dfe3e8;
  --text: #111827;
  --text-2: #374151;
  --muted: #8a94a6;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --green: #15a36e;
  --green-soft: #e9f9f1;
  --red: #e5484d;
  --red-soft: #fdeced;
  --orange: #d97706;
  --orange-soft: #fef6ec;
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--panel);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}
/* 全屏铺满，无边距无圆角 */
#shell {
  height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  overflow: hidden;
}
.hidden { display: none !important; }

/* 登录 */
#login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
#login-form {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 36px; width: 320px; display: flex; flex-direction: column; gap: 14px;
}
#login-form h1 { font-size: 18px; text-align: center; }
#login-form input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
#login-form button {
  padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: #fff;
  font-size: 14px; cursor: pointer;
}
#login-err { color: var(--red); font-size: 12px; text-align: center; min-height: 14px; }

/* 顶栏 */
header {
  display: flex; align-items: center; gap: 20px;
  padding: 0 18px; height: 56px; flex: none;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; padding-right: 4px; }
nav { display: flex; gap: 2px; }
.tab {
  border: 0; background: none; padding: 7px 13px; border-radius: 8px;
  font-size: 13px; cursor: pointer; color: var(--muted); font-weight: 500;
  transition: background .12s, color .12s;
}
.tab:hover { background: var(--subtle); color: var(--text-2); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#statbar { margin-left: auto; display: flex; gap: 7px; font-size: 11px; color: var(--muted); }
#statbar span { background: var(--subtle); border: 1px solid var(--border); border-radius: 8px; padding: 4px 9px; display: inline-flex; align-items: baseline; gap: 4px; white-space: nowrap; }
#statbar b { color: var(--text); font-size: 14px; font-weight: 700; }
#statbar .warn { color: var(--orange); background: var(--orange-soft); border-color: #f6e2c4; }

/* 主体三栏 */
main { flex: 1; display: flex; min-height: 0; }
#contact-pane {
  width: 300px; flex: none; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.pane-tools { padding: 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 9px; }
.pane-tools input {
  padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: 9px; font-size: 13px; width: 100%;
  transition: border-color .12s, box-shadow .12s;
}
.pane-tools input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  border: 1px solid var(--border-strong); background: var(--panel); border-radius: 999px;
  font-size: 11px; padding: 3px 10px; cursor: pointer; color: var(--muted); transition: all .12s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

#contact-list { flex: 1; overflow-y: auto; }
.contact-item {
  padding: 12px 14px 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
  border-left: 3px solid transparent; transition: background .1s;
}
.contact-item:hover { background: var(--subtle); }
.contact-item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.ci-top { display: flex; align-items: center; gap: 6px; }
.ci-name { font-size: 13px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: 11px; color: var(--muted); flex: none; }
.ci-domain { font-size: 11px; color: var(--muted); margin-top: 3px; }
.ci-domain a, .ci-domain { color: var(--muted); }
.ci-snippet { font-size: 12px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  display: inline-block; font-size: 10px; padding: 2px 8px; border-radius: 6px; font-weight: 500;
  background: #f0f1f4; color: var(--muted); flex: none; line-height: 1.4;
}
.badge.st-感兴趣, .badge.st-回复-感兴趣 { background: var(--green-soft); color: var(--green); }
.badge.st-谈价中 { background: var(--orange-soft); color: var(--orange); }
.badge.st-已成交 { background: var(--green); color: #fff; }
.badge.st-拒绝, .badge.st-黑名单 { background: var(--red-soft); color: var(--red); }
.badge.st-已发送, .badge.st-已跟进 { background: var(--accent-soft); color: var(--accent); }
.unread-dot {
  background: var(--red); color: #fff; font-size: 10px; min-width: 17px; height: 17px;
  border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; font-weight: 600;
}

/* 会话区 */
#thread-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
#thread-empty { margin: auto; color: var(--muted); font-size: 14px; }
.thread-loading { margin: auto; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 9px; }
.spinner { width: 15px; height: 15px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
#thread-wrap { display: flex; flex-direction: column; height: 100%; }
#thread-head {
  padding: 13px 22px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; font-size: 13px;
}
#thread-head .th-name { font-weight: 700; font-size: 15px; }
#thread-head .th-mail { color: var(--muted); }
#thread-msgs { flex: 1; overflow-y: auto; padding: 22px 26px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 70%; display: flex; flex-direction: column; gap: 5px; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.in { align-self: flex-start; align-items: flex-start; }
.msg-meta { font-size: 11px; color: var(--muted); display: flex; gap: 8px; align-items: center; padding: 0 2px; }
.msg-bubble {
  padding: 11px 15px; border-radius: 14px; font-size: 13.5px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.msg.out .msg-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 5px; box-shadow: 0 1px 2px rgba(79,70,229,.25); }
.msg.in .msg-bubble { background: var(--panel); border: 1px solid var(--border-strong); border-bottom-left-radius: 5px; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.msg-subject { font-size: 11px; color: var(--muted); }
.msg .stamp { font-size: 10px; }
.stamp.queued { color: var(--orange); }
.stamp.failed { color: var(--red); }
.ai-draft-box {
  align-self: flex-start; max-width: 72%; background: #fffbeb; border: 1px dashed #f59e0b;
  border-radius: 10px; padding: 10px 14px; font-size: 12px; line-height: 1.5; white-space: pre-wrap;
}
.ai-draft-box .adb-head { font-weight: 600; color: var(--orange); margin-bottom: 6px; display: flex; gap: 10px; align-items: center; }
.ai-draft-box button { border: 1px solid #f59e0b; background: #fff; color: var(--orange); border-radius: 6px; font-size: 11px; padding: 2px 8px; cursor: pointer; }

/* 编辑器 */
#composer { background: var(--panel); border-top: 1px solid var(--border); padding: 12px 20px; display: flex; flex-direction: column; gap: 8px; }
#composer input, #composer textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px;
  font-family: inherit; width: 100%;
}
#composer textarea { height: 96px; resize: vertical; }
.composer-actions { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
#send-note { font-size: 11px; color: var(--muted); margin-right: auto; }
.composer-actions button {
  padding: 7px 18px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); font-size: 13px; cursor: pointer;
}
.composer-actions button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.composer-actions button.primary:hover { background: var(--accent-hover); }
.composer-actions button:disabled { opacity: .5; cursor: default; }
#composer textarea:focus, #composer input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* 右侧详情 */
#detail-pane {
  width: 296px; flex: none; background: var(--panel); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 16px 16px 28px; font-size: 13px;
}
#detail-pane h3 {
  font-size: 11px; color: var(--muted); margin: 18px 0 9px; font-weight: 600;
  text-transform: none; letter-spacing: .02em; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
#detail-pane h3:first-child { margin-top: 0; }
.kv { display: flex; justify-content: space-between; padding: 4px 0; gap: 10px; }
.kv .k { color: var(--muted); flex: none; }
.kv .v { text-align: right; word-break: break-all; color: var(--text-2); }
.kv .v a { color: var(--accent); text-decoration: none; font-weight: 500; }
.ef { margin-bottom: 9px; }
.ef label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.ef input, .ef select {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 9px;
  font-size: 13px; font-family: inherit; background: var(--panel); transition: border-color .12s, box-shadow .12s;
}
.ef input:focus, .ef select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.ef2 { display: flex; gap: 8px; }
.ef2 .ef { flex: 1; }
#detail-pane > select, #detail-pane > textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px;
  font-size: 13px; font-family: inherit; background: var(--panel);
}
#detail-pane > select:focus, #detail-pane > textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
#detail-pane textarea { height: 72px; resize: vertical; margin-top: 4px; }
.dr-pill { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 1px 8px; font-weight: 600; }

/* 站点库 */
#view-sites { flex-direction: column; }
.sites-tools { flex-direction: row !important; align-items: center; flex-wrap: wrap; background: var(--panel); border-bottom: 1px solid var(--border); }
.sites-tools input { max-width: 240px; }
.sites-tools input:focus, .sites-tools select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#site-table { flex: 1; overflow: auto; padding: 16px 20px; }
#site-table table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; font-size: 13px; }
#site-table th, #site-table td { text-align: left; padding: 10px 13px; border-bottom: 1px solid var(--border); white-space: nowrap; }
#site-table tbody tr:last-child td { border-bottom: 0; }
#site-table tbody tr:hover { background: var(--subtle); }
#site-table th { background: var(--subtle); color: var(--muted); font-size: 12px; font-weight: 600; position: sticky; top: 0; z-index: 1; }
#site-table td.desc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
#site-table select { border: 1px solid var(--border-strong); border-radius: 7px; padding: 4px 7px; font-size: 12px; background: var(--panel); }
#site-table a { color: var(--accent); text-decoration: none; font-weight: 500; }
#site-table td button { border: 1px solid var(--border-strong); background: var(--panel); border-radius: 7px; font-size: 11px; padding: 4px 11px; cursor: pointer; color: var(--text-2); transition: all .12s; }
#site-table td button:hover { border-color: var(--accent); color: var(--accent); }

/* 同步按钮 */
#btn-sync {
  border: 1px solid var(--border-strong); background: var(--panel); border-radius: 8px;
  font-size: 12px; padding: 6px 13px; cursor: pointer; color: var(--accent); flex: none; font-weight: 500; transition: all .12s;
}
#btn-sync:hover { background: var(--accent-soft); }
#btn-sync:disabled { opacity: .5; cursor: default; }

/* 用户框 */
#userbox { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.ub-name { font-weight: 600; }
.ub-role { color: var(--muted); background: #f1f2f4; border-radius: 999px; padding: 2px 8px; font-size: 11px; }
#userbox button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px;
  font-size: 11px; padding: 3px 10px; cursor: pointer; color: var(--muted);
}

/* 编辑器邮箱选择 */
#compose-mailbox {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
  font-size: 12px; background: var(--panel); max-width: 240px;
}

/* 筛选下拉 */
.pane-tools select {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
  font-size: 12px; background: var(--panel); width: 100%;
}
.sites-tools select { width: auto; }

/* 管理页 */
#view-admin { overflow-y: auto; }
.admin-wrap { padding: 24px; display: flex; flex-direction: column; gap: 28px; max-width: 1080px; }
.admin-section h2 { font-size: 15px; margin-bottom: 12px; }
.admin-section table {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; font-size: 13px;
}
.admin-section th, .admin-section td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
.admin-section th { background: var(--subtle); color: var(--muted); font-size: 12px; font-weight: 600; }
.admin-section tbody tr:hover { background: var(--subtle); }
.admin-section td button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px;
  font-size: 11px; padding: 3px 9px; cursor: pointer; margin-right: 4px;
}
.admin-section td select { border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; font-size: 12px; background: var(--panel); }
.admin-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.admin-form input, .admin-form select {
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 13px;
}
.admin-form button { padding: 7px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); font-size: 13px; cursor: pointer; }
.admin-form button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.admin-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.ok-tag { color: var(--green); background: var(--green-soft); border-radius: 999px; padding: 2px 9px; font-size: 11px; }
.warn-tag { color: var(--orange); background: #fff7ed; border-radius: 999px; padding: 2px 9px; font-size: 11px; }

/* 数字筛选输入 */
.num-filter { max-width: 76px; }
.sites-tools select { font-size: 12px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.table-meta { font-size: 12px; color: var(--muted); padding: 4px 2px 10px; }
#view-publish, #view-suppliers { flex-direction: column; overflow: hidden; }
#publish-table { flex: 1; overflow: auto; padding: 12px 20px; }
#publish-table table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; font-size: 12px; }
#publish-table tbody tr:last-child td { border-bottom: 0; }
#publish-table tbody tr:hover { background: var(--subtle); }
#publish-table th, #publish-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
#publish-table th { background: var(--subtle); color: var(--muted); font-weight: 600; position: sticky; top: 0; z-index: 1; }
#publish-table a { color: var(--accent); text-decoration: none; }
#publish-table button { border: 1px solid var(--border); background: var(--panel); border-radius: 6px; font-size: 11px; padding: 3px 9px; cursor: pointer; }
#supplier-table { overflow: auto; }

/* 站点详情抽屉 */
#site-drawer { position: fixed; inset: 0; z-index: 90; }
#sd-mask { position: absolute; inset: 0; background: rgba(0,0,0,.32); }
#sd-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(880px, 92vw);
  background: var(--panel); box-shadow: -8px 0 28px rgba(0,0,0,.12);
  overflow-y: auto; padding: 20px 24px;
}
.sd-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sd-head > div { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sd-domain { font-size: 17px; font-weight: 700; color: var(--text); text-decoration: none; }
#sd-close {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px;
  font-size: 12px; padding: 5px 14px; cursor: pointer;
}
.sd-metrics { display: flex; gap: 18px; margin: 14px 0 4px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.sd-metrics b { color: var(--text); font-size: 14px; }
.sd-desc { font-size: 12px; color: var(--muted); margin: 8px 0; }
#sd-panel h3 { font-size: 13px; margin: 18px 0 8px; }
.sd-table {
  width: 100%; border-collapse: collapse; border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden; font-size: 12px;
}
.sd-table th, .sd-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.sd-table th { background: #fafbfc; color: var(--muted); font-weight: 600; }
.sd-table a { color: var(--accent); text-decoration: none; }
.sd-table button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px;
  font-size: 11px; padding: 3px 9px; cursor: pointer;
}
.sd-empty { color: var(--muted); text-align: center; }
.sd-sub { font-size: 10px; color: var(--muted); }
#site-table td button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px;
  font-size: 11px; padding: 3px 9px; cursor: pointer;
}

/* 通知 */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 9px 18px; border-radius: 8px;
  font-size: 13px; z-index: 200; opacity: 0; transition: opacity .2s; pointer-events: none;
}
#toast.show { opacity: 1; }
