/* 大管家 Web/H5 · 移动优先 */
/* hidden 属性优先级最高：防止 .modal/.app 等元素的 display 规则覆盖 hidden 导致弹窗关不掉 */
[hidden] { display: none !important; }
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #171a1f;
  --text-2: #5a6068;
  --muted: #8f959d;
  --brand: #2f6fed;
  --brand-2: #5b8cff;
  --brand-soft: #eaf0ff;
  --border: #e6e8ec;
  --user-bubble: #2f6fed;
  --user-text: #ffffff;
  --code-bg: #f4f6f8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 20px rgba(16, 24, 40, .06);
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114;
    --surface: #171a1f;
    --surface-2: #1f2329;
    --text: #e9ecf1;
    --text-2: #a8aeb8;
    --muted: #7d848e;
    --brand: #5b8cff;
    --brand-2: #7aa2ff;
    --brand-soft: #1b2436;
    --border: #262b33;
    --user-bubble: #2f6fed;
    --user-text: #ffffff;
    --code-bg: #1c2026;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* 严格贴合视口，避免 iOS/企微内置浏览器的地址栏高度差导致底部被裁 */
.app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ------------------------------------------------------------ 顶部 */
.hd {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.hd-ava {
  width: 40px; height: 34px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600;
  color: #fff;
  background: linear-gradient(140deg, var(--brand-2), var(--brand));
  box-shadow: 0 2px 8px rgba(47, 111, 237, .28);
  flex: 0 0 auto;
  letter-spacing: .5px;
  white-space: pre-line; text-align: center; line-height: 1.15;
}

.hd-txt { flex: 1 1 auto; min-width: 0; }
.hd-name {
  font-size: 15px; font-weight: 600; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hd-sub {
  display: flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--muted); margin-top: 1px;
}
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px color-mix(in srgb, #22c55e 22%, transparent);
  flex: 0 0 auto;
}
.dot.busy { background: #f59e0b; box-shadow: 0 0 0 2px color-mix(in srgb, #f59e0b 22%, transparent); }

.hd-btn {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: .16s;
}
.hd-btn:active { transform: scale(.93); background: var(--surface-2); }

/* ------------------------------------------------------------ 消息区 */
.chat {
  flex: 1 1 auto;
  min-height: 0;      /* 关键：不加则内容把 footer 顶出视口 */
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 8px;
  scroll-behavior: smooth;
}

.welcome {
  max-width: 100%;
  margin: auto 0;          /* 首屏垂直居中，消息出现后自然回到顶部 */
  padding: 26px 4px 8px;
  text-align: center;
  animation: fade .4s ease both;
}
.welcome.gone { display: none; }

.w-ava {
  width: 60px; height: 56px; margin: 0 auto 14px;
  border-radius: 18px;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 600; color: #fff;
  background: linear-gradient(140deg, var(--brand-2), var(--brand));
  box-shadow: 0 8px 22px rgba(47, 111, 237, .26);
  letter-spacing: 1px;
  white-space: pre-line; text-align: center; line-height: 1.2;
}
.w-title {
  margin: 0 0 6px;
  font-size: 20px; font-weight: 650; letter-spacing: .3px;
}
.w-desc {
  margin: 0 auto 20px;
  font-size: 13.5px; color: var(--text-2);
  max-width: 280px;
}
.w-chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center;
  max-width: min(420px, 100%); margin: 0 auto;
}
.chip {
  max-width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: .16s;
  font-family: inherit;
  line-height: 1.3;
}
.chip:active { transform: scale(.96); background: var(--brand-soft); color: var(--brand); border-color: transparent; }

.msgs { display: flex; flex-direction: column; gap: 16px; padding-bottom: 8px; flex: 0 0 auto; }

.row { display: flex; gap: 9px; animation: rise .26s ease both; }
.row.me { justify-content: flex-end; }

.ava {
  min-width: 34px; height: 28px; border-radius: 9px;
  padding: 0 5px;
  display: grid; place-items: center;
  font-size: 11.5px; font-weight: 600; color: #fff;
  background: linear-gradient(140deg, var(--brand-2), var(--brand));
  flex: 0 0 auto; margin-top: 2px;
  letter-spacing: .5px;
  white-space: pre-line; text-align: center; line-height: 1.1;
}

.bubble {
  max-width: calc(100% - 46px);
  padding: 10px 14px;
  border-radius: 16px 16px 16px 6px;
  background: var(--user-bubble);
  color: var(--user-text);
  font-size: 15px;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .08);
}

.bot { max-width: calc(100% - 40px); min-width: 0; padding-top: 1px; }

.bot .md { font-size: 15px; color: var(--text); word-break: break-word; }
.bot .md > *:first-child { margin-top: 0; }
.bot .md > *:last-child { margin-bottom: 0; }
.bot .md p { margin: 0 0 9px; }
.bot .md h1, .bot .md h2, .bot .md h3, .bot .md h4 {
  margin: 16px 0 8px; font-weight: 650; line-height: 1.35;
}
.bot .md h1 { font-size: 18px; }
.bot .md h2 { font-size: 16.5px; }
.bot .md h3 { font-size: 15.5px; }
.bot .md h4 { font-size: 15px; }
.bot .md strong { font-weight: 650; }
.bot .md ul, .bot .md ol { margin: 6px 0 10px; padding-left: 20px; }
.bot .md li { margin: 3px 0; }
.bot .md li::marker { color: var(--muted); }
.bot .md blockquote {
  margin: 8px 0; padding: 6px 12px;
  border-left: 3px solid var(--brand);
  background: var(--brand-soft);
  border-radius: 0 8px 8px 0;
  color: var(--text-2);
}
.bot .md hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.bot .md a { color: var(--brand); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--brand) 35%, transparent); }
.bot .md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--code-bg);
  padding: 1.5px 5px;
  border-radius: 5px;
  color: var(--text);
}
.bot .md pre {
  margin: 10px 0;
  padding: 12px 13px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.bot .md pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.55; }

.table-wrap {
  margin: 10px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.bot .md table { border-collapse: collapse; width: 100%; font-size: 13px; }
.bot .md th, .bot .md td {
  padding: 8px 11px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.bot .md th { background: var(--surface-2); font-weight: 600; color: var(--text-2); }
.bot .md tr:last-child td { border-bottom: none; }

.caret::after {
  content: "";
  display: inline-block;
  width: 2px; height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--brand);
  animation: blink 1s steps(2, start) infinite;
}

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.3s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .16s; }
.typing i:nth-child(3) { animation-delay: .32s; }

.err {
  margin-top: 6px;
  font-size: 13px;
  color: #dc2626;
}
@media (prefers-color-scheme: dark) { .err { color: #f87171; } }

.retry {
  display: inline-block;
  margin-left: 6px;
  font-size: 12.5px;
  color: var(--brand);
  cursor: pointer;
  text-decoration: underline;
}

/* ------------------------------------------------------------ 输入区 */
.ft {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  padding: 8px 12px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
}

.ft-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 5px 5px 5px 14px;
  box-shadow: var(--shadow);
  transition: border-color .16s;
}
.ft-inner:focus-within { border-color: color-mix(in srgb, var(--brand) 45%, var(--border)); }

#input {
  flex: 1 1 auto;
  border: none;
  outline: none;
  resize: none;
  background: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 21px;
  max-height: 108px;
  padding: 7px 0;
  margin: 0;
}
#input::placeholder { color: var(--muted); }

.send {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border: none;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(140deg, var(--brand-2), var(--brand));
  cursor: pointer;
  transition: .16s;
  box-shadow: 0 2px 8px rgba(47, 111, 237, .3);
}
.send:disabled {
  opacity: .32;
  box-shadow: none;
  cursor: default;
}
.send:not(:disabled):active { transform: scale(.9); }

.ft-tip {
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 5px;
  letter-spacing: .2px;
}

/* ------------------------------------------------------------ 登录门 */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 100;
}
.gate[hidden] { display: none; }

.gate-card { text-align: center; max-width: 320px; }
.gate-ava {
  width: 62px; height: 62px; margin: 0 auto 18px;
  border-radius: 20px;
  display: grid; place-items: center;
  font-size: 26px; font-weight: 600; color: #fff;
  background: linear-gradient(140deg, var(--brand-2), var(--brand));
  box-shadow: 0 10px 26px rgba(47, 111, 237, .28);
  animation: pop .4s cubic-bezier(.2, .9, .3, 1.3) both;
}
.gate-title { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
.gate-desc { margin: 0 0 20px; font-size: 13.5px; color: var(--text-2); line-height: 1.7; }
.gate-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 9px 20px;
  border-radius: 999px;
  cursor: pointer;
}
.spin {
  width: 22px; height: 22px;
  margin: 0 auto;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: none; } }

@media (min-width: 720px) {
  .chat { padding: 22px max(16px, calc(50% - 340px)) 8px; }
  .ft { padding-left: max(12px, calc(50% - 352px)); padding-right: max(12px, calc(50% - 352px)); }
  .hd { padding-left: max(16px, calc(50% - 340px)); padding-right: max(16px, calc(50% - 340px)); }
  .bubble { max-width: 78%; }
}

/* --------------------------------------------------- 嵌入模式（AMIS iframe） */
body.embed { background: var(--surface); }
body.embed .hd { padding-top: 10px; padding-bottom: 9px; }
body.embed .ft-tip { display: none; }
body.embed .chat { padding: 12px 12px 6px; }
body.embed .welcome { padding-top: 18px; }
body.embed .welcome .w-ava {
  width: 52px; height: 46px; border-radius: 15px;
  font-size: 16px; margin-bottom: 11px;
}
body.embed .welcome .w-title { font-size: 17px; margin-bottom: 5px; }
body.embed .w-desc { margin-bottom: 14px; font-size: 13px; }

/* 窄容器（ERP 侧栏）下更紧凑 */
@media (max-width: 420px) {
  body.embed .chat { padding-left: 12px; padding-right: 12px; }
  body.embed .ft { padding-left: 10px; padding-right: 10px; }
  body.embed .chip { font-size: 12.5px; padding: 7px 11px; }
}

/* ==================================================== v2 追加：会话侧栏 */
.side {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 82vw);
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(-102%);
  transition: transform .22s ease;
}
.side.open { transform: translateX(0); }

.side-mask {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(15, 18, 24, .42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.side-hd {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-t)) 14px 10px;
  border-bottom: 1px solid var(--border);
}
.side-title { font-size: 14px; font-weight: 650; letter-spacing: .3px; }
.side-close {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: none; background: none;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
}
.side-close:active { background: var(--surface-2); }

.side-new {
  flex: 0 0 auto;
  margin: 12px 12px 6px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px;
  font-size: 13.5px; font-family: inherit;
  color: var(--brand);
  background: var(--brand-soft);
  border: 1px dashed color-mix(in srgb, var(--brand) 40%, transparent);
  border-radius: 12px;
  cursor: pointer;
  transition: .16s;
}
.side-new:active { transform: scale(.97); }

.side-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 8px 10px;
  -webkit-overflow-scrolling: touch;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  margin: 3px 0;
  border-radius: 11px;
  cursor: pointer;
  transition: .14s;
}
.conv-item:hover, .conv-item:active { background: var(--surface-2); }
.conv-item.active { background: var(--brand-soft); }
.conv-item.active .conv-title { color: var(--brand); font-weight: 600; }

.conv-main { flex: 1 1 auto; min-width: 0; }
.conv-title {
  font-size: 13.5px;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

.conv-ops { flex: 0 0 auto; display: none; gap: 2px; }
.conv-item:hover .conv-ops, .conv-item.active .conv-ops { display: flex; }
.conv-op {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: none; background: none;
  font-size: 13px;
  color: var(--muted);
  border-radius: 7px;
  cursor: pointer;
}
.conv-op:active { background: var(--border); }
@media (hover: none) { .conv-ops { display: flex; } }

.side-empty {
  text-align: center;
  padding: 34px 10px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.8;
}
.side-tip {
  flex: 0 0 auto;
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
  padding: 8px 0 calc(10px + var(--safe-b));
}

/* ---------------------------------------------------- 回到底部 */
.to-bottom {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(96px + var(--safe-b));
  z-index: 40;
  display: flex; align-items: center; gap: 5px;
  padding: 7px 13px;
  font-size: 12.5px; font-family: inherit;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: pointer;
  animation: fade .2s ease both;
}
.to-bottom:active { transform: translateX(-50%) scale(.95); }

/* ---------------------------------------------------- 附件 */
.attach {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  margin-bottom: 1px;
  display: grid; place-items: center;
  border: none; background: none;
  color: var(--muted);
  border-radius: 50%;
  cursor: pointer;
  transition: .15s;
}
.attach:active, .attach:hover { color: var(--brand); background: var(--brand-soft); }

.att-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 4px 7px;
}
.att-chip {
  display: inline-flex; align-items: center; gap: 5px;
  max-width: 100%;
  font-size: 12px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.att-chip.pending { color: var(--muted); }
.att-chip .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip .att-del {
  border: none; background: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 1px;
}
.att-chip .att-del:active { color: #dc2626; }

.my-col { max-width: calc(100% - 46px); display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.row.me .att-chips { justify-content: flex-end; display: flex; flex-wrap: wrap; gap: 5px; }
.row.me .att-chip { font-size: 11.5px; padding: 3px 9px; }

/* 发送/停止按钮 */
.send.stopping {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: none;
  border: 1px solid var(--border);
}

/* ---------------------------------------------------- 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 18, 24, .45);
}
.modal-card {
  width: min(340px, 100%);
  background: var(--surface);
  border-radius: 16px;
  padding: 18px 16px 14px;
  box-shadow: var(--shadow);
  animation: pop .22s cubic-bezier(.2, .9, .3, 1.2) both;
}
.modal-title { margin: 0 0 12px; font-size: 15px; font-weight: 650; }
.modal-input {
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  margin-bottom: 14px;
}
.modal-input:focus { border-color: color-mix(in srgb, var(--brand) 45%, var(--border)); }
.modal-input.readonly { color: var(--text-2); }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; }
.modal-btn {
  font-family: inherit;
  font-size: 13.5px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}
.modal-btn.ghost { background: none; color: var(--text-2); }
.modal-btn:active { transform: scale(.96); }

/* ---------------------------------------------------- 轻提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + var(--safe-b));
  transform: translate(-50%, 8px);
  z-index: 90;
  max-width: 82vw;
  padding: 9px 16px;
  font-size: 13px;
  color: #fff;
  background: rgba(23, 26, 31, .92);
  border-radius: 10px;
  opacity: 0;
  transition: .22s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------- 嵌入模式补充 */
body.embed .side { width: min(280px, 88vw); }
body.embed .to-bottom { bottom: calc(88px + var(--safe-b)); }

/* ==================================================== v3：身份化 UI */

/* 角色徽章（头部 / 身份卡 / 侧栏通用） */
.role-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  vertical-align: 1px;
  white-space: nowrap;
}
.role-badge.lb-sup_admin { color: #722ed1; background: #f9f0ff; border: 1px solid #d3adf7; }
.role-badge.lb-admin     { color: #096dd9; background: #e6f7ff; border: 1px solid #91d5ff; }
.role-badge.lb-normal    { color: #389e0d; background: #f6ffed; border: 1px solid #b7eb8f; }
.role-badge.lb-customer  { color: #d46b08; background: #fff7e6; border: 1px solid #ffd591; }
.role-badge.lb-supplier  { color: #cf1322; background: #fff1f0; border: 1px solid #ffa39e; }
.role-badge.lb-unknown   { color: #8c8c8c; background: #fafafa; border: 1px solid #d9d9d9; }
@media (prefers-color-scheme: dark) {
  .role-badge.lb-sup_admin { background: #231a33; color: #b895e8; }
  .role-badge.lb-admin     { background: #12233d; color: #6ba6f5; }
  .role-badge.lb-normal    { background: #14261a; color: #6fce82; }
  .role-badge.lb-customer  { background: #332312; color: #e89a52; }
  .role-badge.lb-supplier  { background: #361a18; color: #ef8a80; }
  .role-badge.lb-unknown   { background: #20242a; color: #9aa0a8; }
}

/* 欢迎区身份条 */
.w-id {
  max-width: min(440px, 100%);
  margin: 0 auto 18px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  animation: fade .35s ease both;
}
.w-id .w-id-top {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  flex-wrap: wrap;
}
.w-id .w-id-name { font-weight: 650; font-size: 13.5px; }
.w-id .w-id-co { color: var(--text-2); }
.w-id .w-id-scope {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}
.w-id.warn { border-color: #ffd591; background: #fffbe6; }
@media (prefers-color-scheme: dark) { .w-id.warn { border-color: #5c4413; background: #2b2413; } }
.w-id.warn .w-id-scope { color: #ad6800; }
@media (prefers-color-scheme: dark) { .w-id.warn .w-id-scope { color: #d8a03c; } }

/* 无权限/未识别横幅（位于头部下方） */
.deny-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 12.5px;
  line-height: 1.6;
  border-bottom: 1px solid var(--border);
  background: #fff1f0;
  color: #a8071a;
}
.deny-bar.warn { background: #fffbe6; color: #ad6800; }
@media (prefers-color-scheme: dark) {
  .deny-bar { background: #2d1512; color: #ef8a80; }
  .deny-bar.warn { background: #2b2413; color: #d8a03c; }
}

/* 侧栏身份卡 */
.side-user {
  margin: 10px 12px 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.side-user .su-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.side-user .su-ava {
  width: 30px; height: 30px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 650;
  color: #fff;
  background: linear-gradient(140deg, var(--brand-2), var(--brand));
  flex: 0 0 auto;
}
.side-user .su-main { flex: 1 1 auto; min-width: 0; }
.side-user .su-name {
  font-size: 13px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side-user .su-co {
  font-size: 11px; color: var(--muted);
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side-user .su-scope {
  margin-top: 7px;
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.65;
}

/* ==================================================== 桌面三栏（非嵌入 iframe） */
body.desktop .side {
  position: static;
  transform: none;
  width: 268px;
  flex: 0 0 268px;
  box-shadow: none;
  border-right: 1px solid var(--border);
}
body.desktop .side-mask { display: none !important; }
body.desktop .side-close { display: none; }
body.desktop .hd-btn#btnSide { display: none; }
body.desktop .app { flex-direction: row; }
.col {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.desktop .chat { padding: 24px max(24px, calc(50% - 380px)) 10px; }
body.desktop .ft { padding-left: max(18px, calc(50% - 392px)); padding-right: max(18px, calc(50% - 392px)); }
body.desktop .hd { padding-left: max(18px, calc(50% - 380px)); padding-right: max(18px, calc(50% - 380px)); }
body.desktop .deny-bar { padding-left: max(18px, calc(50% - 380px)); padding-right: max(18px, calc(50% - 380px)); }
body.desktop .w-id { margin-bottom: 22px; }

/* 嵌入模式不启用桌面三栏（iframe 宽度不受控，保持单列） */
body.embed.desktop .side {
  position: fixed;
  transform: translateX(-102%);
  width: min(280px, 88vw);
  box-shadow: var(--shadow);
  border-right: none;
}
body.embed.desktop .side-mask { display: block; }
body.embed.desktop .side-close { display: grid; }
body.embed.desktop .hd-btn#btnSide { display: grid; }
body.embed.desktop .app { flex-direction: column; }
body.embed.desktop .col { flex: 1 1 auto; }

/* ---------------------------------------------------------------- 登录页 */
.login {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + var(--safe-b));
  background: var(--bg);
  overflow: auto;
}
.login[hidden] { display: none; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-ava {
  width: 56px; height: 56px; margin: 0 auto 14px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-size: 20px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(47, 111, 237, .28);
  white-space: pre-line; text-align: center; line-height: 1.2;
}
.login-title { margin: 0 0 6px; font-size: 21px; font-weight: 600; color: var(--text); }
.login-desc { margin: 0 0 22px; font-size: 13px; color: var(--text-2); }
.login-form { text-align: left; }
.lf { display: block; margin-bottom: 14px; }
.lf-label { display: block; margin: 0 0 6px 2px; font-size: 12.5px; color: var(--text-2); }
.lf input {
  width: 100%; box-sizing: border-box;
  height: 46px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-size: 15px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.lf input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.lg-remember {
  display: flex; align-items: center; gap: 8px;
  margin: 2px 0 16px; font-size: 13px; color: var(--text-2);
  cursor: pointer; user-select: none;
}
.lg-remember input { width: 16px; height: 16px; accent-color: var(--brand); }
.lg-error {
  margin: 0 0 12px; padding: 9px 12px;
  border-radius: 10px; background: #fdecec; color: #b42318;
  font-size: 13px; line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
  .lg-error { background: #3a1d1d; color: #ffb4ab; }
}
.login-btn {
  width: 100%; height: 48px;
  border: 0; border-radius: 12px;
  background: var(--brand); color: #fff;
  font-size: 15.5px; font-weight: 500; letter-spacing: 2px;
  cursor: pointer; transition: opacity .15s, transform .1s;
}
.login-btn:active { transform: scale(.985); }
.login-btn[disabled] { opacity: .6; cursor: default; }
.login-pick { text-align: left; }
.lp-tip { margin: 0 0 12px; font-size: 13.5px; color: var(--text-2); line-height: 1.6; }
.lp-list { display: flex; flex-direction: column; gap: 10px; }
.lp-item {
  display: flex; flex-direction: column; gap: 3px;
  padding: 13px 15px; text-align: left;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.lp-item:hover { border-color: var(--brand); background: var(--brand-soft); }
.lp-item b { font-size: 14.5px; font-weight: 500; }
.lp-item span { font-size: 12.5px; color: var(--muted); }
.login-foot { margin: 20px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* 全屏态：隐藏次要提示，铺满视口 */
body.fs .ft-tip { display: none; }
body.fs .app { height: 100dvh; }

/* 侧栏身份卡：退出登录 */
.su-out {
  margin-top: 10px; padding: 7px 14px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text-2);
  font-size: 12.5px; cursor: pointer;
}
.su-out:hover { border-color: #e0b4b4; color: #b42318; }

/* ---------------------------------------------- 品牌标记：完整文字，不截断 */
/* 品牌字 2+2 上下排列：宽度不再随字数拉伸，只缩字号 */
.hd-ava[data-len="3"] { font-size: 12px; letter-spacing: 0; font-weight: 600; }
.hd-ava[data-len="4"] { font-size: 11px; letter-spacing: 0; font-weight: 600; }
.w-ava[data-len="3"] { font-size: 17px; letter-spacing: 0; }
.w-ava[data-len="4"] { font-size: 16px; letter-spacing: 0; }
.login-ava[data-len="3"] { font-size: 15px; letter-spacing: 0; }
.login-ava[data-len="4"] { font-size: 14px; letter-spacing: 0; }

/* ---------------------------------------------- 使用方账户（右上角，与服务方品牌分开） */
.hd-user {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  margin-left: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px; font-weight: 600;
  display: grid; place-items: center;
  cursor: pointer;
}
.hd-user:active { background: var(--border); }

.user-mask {
  position: fixed; inset: 0; z-index: 85;
  background: rgba(15, 18, 24, .28);
}
.user-pop {
  position: fixed; z-index: 86;
  top: calc(58px + var(--safe-t)); right: 14px;
  width: 236px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: pop .18s cubic-bezier(.2, .9, .3, 1.2) both;
}
.up-top { display: flex; align-items: center; gap: 10px; }
.up-ava {
  flex: 0 0 auto; width: 36px; height: 36px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
  font-size: 15px; font-weight: 600;
}
.up-main { min-width: 0; flex: 1 1 auto; }
.up-name { font-size: 14px; font-weight: 600; color: var(--text); }
.up-co { margin-top: 2px; font-size: 12px; color: var(--muted); }
.up-badge { margin-top: 10px; }
.up-actions { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.up-out {
  width: 100%; height: 36px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text-2);
  font-size: 13.5px; cursor: pointer;
}
.up-out:hover { border-color: #e0b4b4; color: #b42318; }
.up-out[disabled] { opacity: .55; cursor: default; }

/* 弹窗说明文案（删除确认等） */
.modal-desc {
  margin: -4px 0 12px;
  font-size: 13.5px; line-height: 1.6; color: var(--text-2);
  word-break: break-word;
}

/* ---------------------------------------------- 智能体回传文件卡片 */
.file-card {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2);
  text-decoration: none; color: inherit;
  max-width: 420px;
}
.file-card:hover { border-color: var(--brand); background: var(--brand-soft); }
.file-ico {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--surface); color: var(--brand);
  font-size: 15px;
}
.file-main { min-width: 0; flex: 1 1 auto; }
.file-name { font-size: 13.5px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { margin-top: 2px; font-size: 11.5px; color: var(--muted); }
.file-dl { flex: 0 0 auto; font-size: 12.5px; color: var(--brand); }
.ava[data-len="3"] { font-size: 9px; letter-spacing: 0; padding: 0 4px; }
.ava[data-len="4"] { font-size: 8.5px; letter-spacing: 0; padding: 0 4px; }
.file-wrap { margin-top: 2px; }
