:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --surface-3: #f0f2f5;
  --border: #e4e7eb;
  --border-strong: #d0d5dc;
  --text: #1a1d21;
  --text-2: #5b6270;
  --text-3: #8b929e;
  --accent: #185fa5;
  --accent-hover: #0c447c;
  --accent-soft: #e6f1fb;
  --green: #0f6e56;
  --green-soft: #e1f5ee;
  --amber: #854f0b;
  --amber-soft: #faeeda;
  --red: #a32d2d;
  --red-soft: #fcebeb;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 28px rgba(16, 24, 40, .14);
  --font: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- 登录 */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 28px 26px;
}

.login-card h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 4px;
}

.login-card p.sub {
  margin: 0 0 20px;
  color: var(--text-3);
  font-size: 12px;
}

/* 登录卡片：记住企业 ID + 切换登录方式的次级按钮 */
.login-card .remember {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: -6px 0 16px;
  color: var(--text-3);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.login-card .remember input { accent-color: var(--accent); }

.login-card .linkbtn {
  display: block;
  margin: 14px auto 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.login-card .linkbtn:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- 布局 */
.shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 14px; }
.brand .dot {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
}
.topbar .spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
  background: var(--surface-3); color: var(--text-2);
}
.pill.ok { background: var(--green-soft); color: var(--green); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.err { background: var(--red-soft); color: var(--red); }
.pill.on { background: var(--accent-soft); color: var(--accent); }
.pill .led { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.body { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 176px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.navitem {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-2); font-weight: 500;
  border: none; background: none; text-align: left; width: 100%;
}
.navitem:hover { background: var(--surface-3); color: var(--text); }
.navitem.active { background: var(--accent-soft); color: var(--accent); }
.navitem .ico { width: 15px; text-align: center; opacity: .85; }
.navitem .badge {
  margin-left: auto; background: var(--red); color: #fff;
  border-radius: 999px; padding: 0 6px; font-size: 10px; font-weight: 600;
  min-width: 17px; text-align: center;
}

.main { flex: 1; min-width: 0; overflow: hidden; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
.view.flush { padding: 0; overflow: hidden; }

.view-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
}
.view-head h2 { font-size: 15px; font-weight: 600; margin: 0; }
.view-head .spacer { flex: 1; }

/* ---------------------------------------------------------------- 组件 */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  cursor: pointer; font-weight: 500; font-size: 12.5px;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { padding: 4px 9px; font-size: 11.5px; }
.btn.danger { color: var(--red); border-color: #f0c9c9; }
.btn.danger:hover { background: var(--red-soft); }

.input, .textarea, .select {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); outline: none;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 72px; line-height: 1.6; }
.field { margin-bottom: 12px; }
.field label {
  display: block; font-size: 12px; font-weight: 500;
  color: var(--text-2); margin-bottom: 5px;
}
.hint { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-head {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px;
}
.card-head .spacer { flex: 1; }
.card-body { padding: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 13px;
}
.stat .k { font-size: 11.5px; color: var(--text-3); }
.stat .v { font-size: 21px; font-weight: 600; margin-top: 2px; letter-spacing: -.3px; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--text-3); margin-left: 3px; }

/* ---------------------------------------------------------------- 工作台 */
.inbox { display: grid; grid-template-columns: 296px minmax(0, 1fr) 268px; height: 100%; }

.conv-list {
  border-right: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}
.conv-filter { padding: 10px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.convs { flex: 1; overflow: auto; }

.conv {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; display: grid; gap: 3px;
}
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.conv .row1 { display: flex; align-items: center; gap: 6px; }
.conv .who {
  font-weight: 500; font-size: 12.5px; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv .time { font-size: 10.5px; color: var(--text-3); flex: none; }
.conv .prev {
  font-size: 11.5px; color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv.unread .who { font-weight: 600; }
.conv.unread .prev { color: var(--text-2); }
.conv .tags { display: flex; gap: 4px; align-items: center; }
.tag {
  font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: var(--surface-3); color: var(--text-2);
}
.tag.s3 { background: var(--green-soft); color: var(--green); }
.tag.s4 { background: var(--surface-3); color: var(--text-3); }
.tag.pending { background: var(--amber-soft); color: var(--amber); }
.dot-unread {
  background: var(--red); color: #fff; border-radius: 999px;
  font-size: 10px; font-weight: 600; padding: 0 5px; min-width: 16px; text-align: center;
}

.chat { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.chat-head {
  flex: none; padding: 10px 14px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.chat-head .who { font-weight: 600; font-size: 13.5px; }
.chat-head .sub { font-size: 11px; color: var(--text-3); font-family: var(--mono); }
.chat-head .spacer { flex: 1; }

.msgs { flex: 1; overflow: auto; padding: 16px 16px 4px; }
.msgs-inner { display: flex; flex-direction: column; gap: 10px; max-width: 720px; margin: 0 auto; }

.msg { display: flex; flex-direction: column; max-width: 74%; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.sys { align-self: center; max-width: 90%; align-items: center; }
.msg .who {
  font-size: 10.5px; color: var(--text-3); margin: 0 4px 3px;
}
.bubble {
  padding: 8px 12px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-word;
}
.msg.in .bubble { border-bottom-left-radius: 4px; }
.msg.out .bubble {
  background: var(--accent); border-color: var(--accent); color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.sys .bubble {
  background: var(--surface-3); border-color: transparent;
  color: var(--text-3); font-size: 11.5px; padding: 4px 10px; border-radius: 999px;
}
.msg .meta { font-size: 10.5px; color: var(--text-3); margin: 3px 4px 0; }
.msg.out .meta { text-align: right; }

.composer { flex: none; background: var(--surface); border-top: 1px solid var(--border); padding: 10px 14px 12px; }
.quick { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 140px; }
.composer .hint { display: flex; justify-content: space-between; }

/* ------------------------------------------------------------- 图文卡片 */
.tiny { font-size: 11px; color: var(--text-3); font-weight: 400; }

.cardform {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); padding: 10px 12px 12px; margin-bottom: 9px;
}
.cardform-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.cardform-head b { font-size: 12.5px; }
.cardform-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.cardform-grid .field { margin: 0; }
.cardform-foot {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--border);
}

/* 卡片库：已存的卡片，缩略图 + 标题 + 载入/发送/删 */
.cardlib {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); padding: 8px 9px; margin-bottom: 9px;
}
.cardlib-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.cardlib-head b { font-size: 12px; }
.cardlib-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 6px; max-height: 176px; overflow-y: auto;
}
.cardlib-item {
  display: flex; gap: 8px; align-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: 5px 6px; min-width: 0;
}
.cardlib-item.is-loaded { border-color: var(--accent); background: var(--accent-soft, var(--surface-2)); }
.cardlib-thumb {
  width: 40px; height: 40px; flex: none; border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong); background: var(--surface);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: 10px; color: var(--text-3);
}
.cardlib-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cardlib-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.cardlib-title {
  font-size: 12px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cardlib-url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cardlib-acts { display: flex; flex-direction: column; gap: 3px; flex: none; }

.thumbrow { display: flex; gap: 9px; align-items: center; }
.thumbbox {
  width: 46px; height: 46px; flex: none; border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong); background: var(--surface);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: 10px; color: var(--text-3);
}
.thumbbox:empty::after { content: '无图'; }
.thumbbox img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbmeta { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; min-width: 0; }
.thumbmeta .tiny { word-break: break-all; }

/* 聊天气泡里的卡片 */
.card {
  display: flex; gap: 10px; align-items: stretch; max-width: 320px;
  padding: 9px; border-radius: 12px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); box-shadow: var(--shadow);
}
.card:hover { border-color: var(--accent); }
.card.nolink { background: var(--surface-3); }
.card-thumb {
  width: 52px; flex: none; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; letter-spacing: .5px;
}
.card-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.card-title { font-size: 12.5px; font-weight: 600; line-height: 1.35; }
.card-desc {
  font-size: 11.5px; color: var(--text-2); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-host {
  font-size: 10.5px; color: var(--text-3); margin-top: auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg.out .card { border-bottom-right-radius: 4px; }
.msg.in .card { border-bottom-left-radius: 4px; }

@media (max-width: 860px) {
  .cardform-grid { grid-template-columns: 1fr; }
}

.side { border-left: 1px solid var(--border); background: var(--surface); overflow: auto; }
.side-sec { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.side-sec h4 {
  font-size: 11px; text-transform: none; letter-spacing: .3px;
  color: var(--text-3); margin: 0 0 8px; font-weight: 600;
}
.kv { display: grid; grid-template-columns: 78px 1fr; gap: 4px 8px; font-size: 11.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-all; font-family: var(--mono); font-size: 11px; }
.state-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }

.empty {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  color: var(--text-3); text-align: center; padding: 24px;
}
.empty .big { font-size: 14px; font-weight: 500; color: var(--text-2); }
/* 企微原始报错，字号小、可换行，便于复制去搜错误码 */
.empty .raw {
  font-size: 11px; font-family: var(--mono); color: var(--text-3);
  word-break: break-all; max-width: 520px; line-height: 1.5;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 8px; margin-top: 2px;
}

/* ---------------------------------------------------------------- 规则 */
.rule {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 12px; background: var(--surface-2);
}
.rule + .rule { margin-top: 9px; }
.rule-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.rule-head .idx {
  font-size: 11px; font-weight: 600; color: var(--text-3);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 7px;
}
.rule-head .spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.acct {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 13px; background: var(--surface-2);
}
.acct + .acct { margin-top: 9px; }
.acct .name { font-weight: 600; font-size: 13px; }
.acct .kfid { font-family: var(--mono); font-size: 11px; color: var(--text-3); margin: 2px 0 8px; }
.acct .acts { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- 弹窗 */
.mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .42);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; max-height: 88vh; overflow: auto;
}
.modal-head {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; font-weight: 600;
}
.modal-head .spacer { flex: 1; }
.modal-body { padding: 16px; }
.modal-foot {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}
.qr-box {
  width: 188px; height: 188px; margin: 0 auto 12px;
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px;
}
.qr-box svg { display: block; width: 100%; height: 100%; }
.copyline { display: flex; gap: 6px; }
.copyline .input { font-family: var(--mono); font-size: 11.5px; }

/* ---------------------------------------------------------------- 提示 */
.toasts {
  position: fixed; right: 18px; bottom: 18px; display: flex;
  flex-direction: column; gap: 8px; z-index: 90;
}
.toast {
  background: #22262c; color: #fff; padding: 9px 14px;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  font-size: 12.5px; max-width: 340px; animation: toast-in .16s ease-out;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

@media (max-width: 1180px) {
  .inbox { grid-template-columns: 260px minmax(0, 1fr); }
  .side { display: none; }
}
@media (max-width: 860px) {
  .sidebar { width: 52px; padding: 8px 6px; }
  .navitem span.lbl { display: none; }
  .navitem { justify-content: center; }
  .inbox { grid-template-columns: 210px minmax(0, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
}
