:root {
  --bg: #f4efe5;
  --surface: #fffdf9;
  --surface-2: #faf6ee;
  --ink: #262019;
  --ink-soft: #6f6457;
  --line: #e9dfd0;
  --line-2: #f0e8db;
  --gold: #b58a45;
  --gold-deep: #916b2d;
  --gold-soft: #f7ecd7;
  --green: #2f7d63;
  --red: #b64b44;
  --shadow: 0 24px 70px rgba(54, 40, 22, .10);
  --radius: 18px;
  --radius-sm: 12px;
  --topbar-h: 70px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden], #app[hidden], #login-overlay[hidden] { display: none !important; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(181, 138, 69, .13), transparent 70%),
    radial-gradient(600px 500px at -10% 100%, rgba(181, 138, 69, .08), transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--gold-deep); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- shared top bar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 0 clamp(18px, 4vw, 44px);
  border-bottom: 1px solid rgba(233, 223, 208, .8);
  background: rgba(255, 253, 249, .78);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(145deg, #d8b87a, #a87935);
  box-shadow: 0 8px 18px rgba(168, 121, 53, .24);
  letter-spacing: -.06em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-text strong { font-size: 16px; letter-spacing: .04em; white-space: nowrap; }
.brand-text small { color: var(--ink-soft); font-size: 10px; letter-spacing: .18em; margin-top: 4px; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  white-space: nowrap;
}
.status-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(47, 125, 99, .12); }
.status-dot.waiting { background: var(--gold); box-shadow: 0 0 0 3px rgba(181, 138, 69, .16); }
.status-dot.closed { background: #a9a096; box-shadow: none; }
.status-dot.error { background: var(--red); box-shadow: 0 0 0 3px rgba(182, 75, 68, .14); }
.status-pill.warn { color: #8a6429; border-color: #ecd9b7; background: #fdf7ea; }
.status-pill.error { color: #8f2f2a; border-color: #f0d3ce; background: #fdf1ef; }

/* ---------- shared buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 13px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover:not(:disabled) { border-color: #d8c39d; background: var(--gold-soft); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--gold-deep); border-color: var(--gold-deep); color: #fff; }
.btn.danger { color: var(--red); border-color: #ecd1cc; background: #fff8f6; }
.btn.danger:hover:not(:disabled) { background: #fdeceb; border-color: #e3b8b2; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.is-loading, .send-btn.is-loading { cursor: progress; }
.btn.is-loading::before,
.send-btn.is-loading::before {
  content: "";
  width: 12px;
  height: 12px;
  flex: none;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin .65s linear infinite;
}
.send-btn {
  border: 0;
  height: 46px;
  padding: 0 21px;
  border-radius: 13px;
  background: linear-gradient(145deg, #d2af6e, #a87935);
  color: #fff;
  font-weight: 700;
  letter-spacing: .05em;
  box-shadow: 0 8px 18px rgba(168, 121, 53, .23);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
  transition: filter .15s, opacity .15s;
}
.send-btn:hover:not(:disabled) { filter: brightness(1.05); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--ink-soft); }

/* ---------- banners / toasts / states ---------- */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-soft);
}
.banner[hidden] { display: none !important; }
.banner-error { color: #8f2f2a; background: #fdf1ef; border-color: #f0d3ce; }
.banner-info { color: #7a5a20; background: #fbf4e4; border-color: #ecd9b7; }
.banner .banner-text { flex: 1; min-width: 0; line-height: 1.5; word-break: break-word; }
.banner .btn { flex: none; }

.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 90;
  width: min(420px, calc(100% - 24px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: 100%;
  background: #2f2a23;
  color: #fff;
  padding: 10px 14px;
  border-radius: 11px;
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .22);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #8f2f2a; }
.toast.success { background: #2f6b52; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
  padding: 32px 16px;
  line-height: 1.6;
  min-height: 110px;
}
.empty-state .empty-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--gold-soft);
  color: var(--gold-deep);
  border: 1px solid #eddcc0;
  font-size: 19px;
  margin-bottom: 2px;
}
.empty-state .empty-title { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink); word-break: break-word; }
.empty-state .empty-desc { margin: 0; font-size: 12px; color: var(--ink-soft); max-width: 300px; }
.empty-state .btn { margin-top: 8px; }

.skeleton-line {
  height: 11px;
  border-radius: 6px;
  background: linear-gradient(90deg, #f1eadf 25%, #f9f4ea 37%, #f1eadf 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skeleton-line.short { width: 58%; }
.skeleton-line.tiny { width: 34%; }
.skeleton-list { display: flex; flex-direction: column; gap: 12px; padding: 14px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.mobile-only { display: none !important; }

/* ---------- visitor ---------- */
.visitor-page { min-height: 100%; }
.visitor-shell {
  width: min(940px, calc(100% - 28px));
  margin: 0 auto;
  padding: clamp(22px, 5vw, 54px) 0 calc(clamp(22px, 5vw, 54px) + env(safe-area-inset-bottom, 0px));
}
.visitor-hero { margin: 0 0 18px; }
.visitor-hero h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 42px);
  letter-spacing: -.04em;
  line-height: 1.1;
}
.visitor-hero p { margin: 10px 0 0; color: var(--ink-soft); font-size: 14px; }
.chat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.chat-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.avatar {
  width: 36px; height: 36px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(145deg, #d8b87a, #a87935); color: #fff; font-weight: 800;
}
.chat-card-header h2 { font-size: 14px; margin: 0; }
.chat-card-header p { margin: 3px 0 0; font-size: 11px; color: var(--ink-soft); }
.messages {
  height: min(52vh, 520px);
  height: min(52dvh, 520px);
  min-height: 280px;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.msg-row { display: flex; gap: 8px; align-items: flex-end; }
.msg-row > div { max-width: min(78%, 560px); min-width: 0; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.system { justify-content: center; }
.msg-row.system .bubble {
  max-width: none;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12px;
}
.msg-row.system .msg-meta { display: none; }
.bubble {
  max-width: 100%;
  padding: 11px 14px;
  border-radius: 15px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  width: fit-content;
  background: #f4eee3;
  border: 1px solid #eee3d2;
  color: var(--ink);
}
.msg-row.mine .bubble {
  background: var(--gold);
  border-color: var(--gold);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.msg-row:not(.mine):not(.system) .bubble { border-bottom-left-radius: 5px; }
.msg-meta { font-size: 10px; color: #a69a8a; margin: 4px 3px 0; }
.msg-row.mine .msg-meta { text-align: right; }
.composer {
  border-top: 1px solid var(--line);
  padding: 13px;
  display: flex;
  gap: 9px;
  align-items: flex-end;
  background: var(--surface);
}
.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 14px;
  outline: none;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
.composer textarea:focus { border-color: #d4b784; box-shadow: 0 0 0 3px rgba(181, 138, 69, .12); }
.composer textarea:disabled { opacity: .65; cursor: not-allowed; }
.hint {
  padding: 0 22px 16px;
  font-size: 11px;
  color: #9b8f7f;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.char-count { flex: none; font-variant-numeric: tabular-nums; color: #a69a8a; }
.char-count.limit { color: var(--red); font-weight: 700; }

/* ---------- agent ---------- */
.agent-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.agent-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
}
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(54, 40, 22, .05); min-height: 0; }
.session-side { display: flex; flex-direction: column; overflow: hidden; }
.session-head { padding: 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.session-head h2 { font-size: 14px; margin: 0; }
.session-head .head-actions { display: flex; align-items: center; gap: 8px; }
.session-head .btn { padding: 5px 9px; font-size: 11px; }
.count { color: var(--ink-soft); font-size: 11px; }
.session-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.session-item {
  text-align: left;
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  padding: 11px 12px;
  color: var(--ink);
}
.session-item:hover { background: var(--surface-2); border-color: var(--line); }
.session-item.active { background: var(--gold-soft); border-color: #dfc99f; }
.session-item .line1 { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 700; min-width: 0; }
.session-item .line1 span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .line2 { margin-top: 4px; color: var(--ink-soft); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 10px; border-radius: 999px; padding: 3px 7px; font-weight: 600; flex: none; }
.badge.waiting { color: #8a6429; background: #f5e7c9; }
.badge.serving { color: #24644f; background: #e4f2ea; }
.badge.closed { color: #746b60; background: #efeae3; }
.chat-panel { display: flex; flex-direction: column; overflow: hidden; }
.chat-panel-head { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-panel-head h2 { margin: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-panel-head p { margin: 3px 0 0; font-size: 11px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-panel-head .spacer { flex: 1; }
.chat-panel-head > div { min-width: 0; }
.back-btn { padding: 7px 10px; font-size: 14px; line-height: 1; }
.agent-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 11px; background: #fcfaf5; overscroll-behavior: contain; }
.agent-composer { border-top: 1px solid var(--line); padding: 12px; display: flex; gap: 9px; align-items: flex-end; }
.agent-composer textarea { flex: 1; min-width: 0; min-height: 44px; max-height: 130px; resize: none; border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; outline: none; background: var(--surface); }
.agent-composer textarea:focus { border-color: #d4b784; box-shadow: 0 0 0 3px rgba(181, 138, 69, .11); }
.agent-composer textarea:disabled { opacity: .65; cursor: not-allowed; }
.agent-placeholder { flex: 1; display: grid; place-items: center; color: var(--ink-soft); font-size: 13px; padding: 24px; }
.login-overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(38, 32, 25, .55); backdrop-filter: blur(9px); padding: 20px; z-index: 30; overflow-y: auto; }
.login-card { width: min(410px, 100%); max-height: calc(100dvh - 40px); overflow-y: auto; background: var(--surface); border: 1px solid rgba(233, 223, 208, .9); border-radius: 22px; padding: 28px; box-shadow: 0 30px 90px rgba(0, 0, 0, .26); }
.login-card h1 { font-size: 22px; margin: 0 0 8px; letter-spacing: -.03em; }
.login-card p { margin: 0 0 20px; color: var(--ink-soft); font-size: 13px; line-height: 1.6; }
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.field input { height: 43px; border: 1px solid var(--line); border-radius: 11px; padding: 0 13px; background: var(--surface-2); outline: none; }
.field input:focus { border-color: #d4b784; box-shadow: 0 0 0 3px rgba(181, 138, 69, .11); }
.login-card .send-btn { width: 100%; height: 44px; }
.error-text { min-height: 18px; color: var(--red); font-size: 12px; margin: 9px 0 0; }
.error-text:empty { min-height: 0; margin: 0; }

/* ---------------- 运营后台 ---------------- */
.admin-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.admin-shell { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(260px, 310px) minmax(0, 1fr); gap: 14px; padding: 14px; }
.admin-sidebar { display: flex; flex-direction: column; overflow: hidden; }
.admin-form { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.admin-form input { flex: 1; min-width: 0; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0 11px; background: var(--surface-2); outline: none; }
.admin-form input:focus { border-color: #d4b784; box-shadow: 0 0 0 3px rgba(181, 138, 69, .11); }
.admin-form .send-btn { height: 40px; padding: 0 14px; font-size: 12px; }
.admin-form-stack { flex-direction: column; border-bottom: 0; border-top: 1px solid var(--line); margin-top: auto; }
.admin-form-stack .send-btn { width: 100%; }
.tenant-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.tenant-item { text-align: left; min-width: 0; border: 1px solid transparent; border-radius: 12px; background: transparent; padding: 12px; color: var(--ink); }
.tenant-item:hover { background: var(--surface-2); border-color: var(--line); }
.tenant-item.active { background: var(--gold-soft); border-color: #dfc99f; }
.tenant-item strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tenant-item small { display: block; color: var(--ink-soft); font-size: 10px; margin-top: 4px; word-break: break-all; }
.admin-content { overflow-y: auto; padding: 22px; }
.admin-content > .agent-placeholder { min-height: 46vh; padding: 32px 18px; text-align: center; line-height: 1.7; }
.admin-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.admin-head-main { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.admin-head-titles { min-width: 0; }
.admin-head h1 { font-size: 24px; letter-spacing: -.03em; margin: 0; word-break: break-word; }
.admin-head p { margin: 6px 0 0; font-size: 11px; word-break: break-all; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.admin-card { border: 1px solid var(--line-2); border-radius: 14px; background: var(--surface); overflow: hidden; display: flex; flex-direction: column; }
.admin-card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.admin-card-head h2 { margin: 0; font-size: 14px; }
.admin-list { padding: 8px 16px; min-height: 100px; }
.admin-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.admin-row:last-child { border-bottom: 0; }
.admin-row .grow { flex: 1; min-width: 0; }
.admin-row strong { display: block; font-size: 13px; }
.admin-row small { display: block; color: var(--ink-soft); font-size: 10px; margin-top: 3px; word-break: break-all; }
.admin-row .btn { padding: 6px 9px; font-size: 11px; }
.admin-row .row-actions { display: flex; gap: 6px; flex: none; }
.admin-full-btn { width: calc(100% - 32px); margin: 0 16px 14px; }
.admin-note { padding: 0 16px 14px; font-size: 11px; margin: 0; }
.admin-note code { background: var(--gold-soft); color: var(--gold-deep); padding: 2px 5px; border-radius: 5px; font-size: 10px; }
.admin-modal { position: fixed; inset: 0; background: rgba(38, 32, 25, .55); backdrop-filter: blur(8px); display: grid; place-items: center; padding: 18px; z-index: 50; }
.admin-modal-card { width: min(500px, 100%); max-height: calc(100dvh - 36px); overflow-y: auto; background: var(--surface); border-radius: 18px; padding: 22px; box-shadow: 0 30px 90px rgba(0,0,0,.28); }
.admin-modal-card h2 { margin: 0 0 6px; font-size: 18px; }
.admin-modal-card p { margin: 0 0 12px; font-size: 12px; }
.admin-modal-card textarea { width: 100%; min-height: 84px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: vertical; background: var(--surface-2); color: var(--ink); font-family: Consolas, monospace; font-size: 12px; }
.admin-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.admin-readonly { color: var(--ink-soft); font-size: 11px; }

/* ---------- tablet ---------- */
@media (max-width: 960px) {
  .agent-main { grid-template-columns: minmax(240px, 280px) minmax(0, 1fr); gap: 10px; padding: 10px; }
  .admin-shell { grid-template-columns: minmax(230px, 260px) minmax(0, 1fr); gap: 10px; padding: 10px; }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-content { padding: 16px; }
}

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  :root { --topbar-h: 60px; }
  .topbar { padding: 0 14px; gap: 9px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }
  .brand-text strong { font-size: 15px; letter-spacing: .02em; }
  .brand-text small { display: none; }
  .status-pill { padding: 6px 10px; font-size: 11px; gap: 6px; }
  .topbar .btn { padding: 7px 11px; font-size: 11px; }

  .mobile-only { display: inline-flex !important; }

  /* visitor */
  .visitor-shell { width: calc(100% - 20px); padding: 16px 0 calc(16px + env(safe-area-inset-bottom, 0px)); }
  .visitor-hero { margin-bottom: 12px; }
  .visitor-hero h1 { font-size: clamp(24px, 7vw, 32px); }
  .visitor-hero p { font-size: 13px; margin-top: 6px; }
  .chat-card { border-radius: 20px; }
  .chat-card-header { padding: 14px 16px; }
  .messages { height: min(56dvh, 480px); min-height: 220px; padding: 15px; gap: 11px; }
  .bubble { max-width: 84%; font-size: 14.5px; }
  .composer { padding: 10px; gap: 8px; }
  .composer textarea { font-size: 16px; padding: 11px 12px; }
  .send-btn { height: 46px; padding: 0 16px; }
  .hint { padding: 0 16px 12px; font-size: 10.5px; }

  /* agent: 列表 <-> 会话 单屏切换 */
  .agent-main { display: block; padding: 8px; }
  .agent-main > .panel { height: 100%; }
  .session-side { display: flex; }
  .chat-panel { display: none; }
  .agent-main.chat-open .session-side { display: none; }
  .agent-main.chat-open .chat-panel { display: flex; }
  .session-side { max-height: none; }
  .session-head { padding: 13px 14px; }
  .session-list { padding: 6px; }
  .chat-panel-head { padding: 12px; gap: 9px; flex-wrap: wrap; }
  .chat-panel-head .spacer { display: none; }
  .chat-panel-head .back-btn { order: -1; }
  .agent-messages { padding: 14px; }
  .agent-composer { padding: 10px; gap: 8px; }
  .agent-composer textarea { font-size: 16px; padding: 11px 12px; }
  .login-overlay { padding: 14px; align-items: end; }
  .login-card { padding: 22px; border-radius: 20px; max-height: calc(100dvh - 28px); }

  /* admin: 租户列表 <-> 详情 单屏切换 */
  .admin-shell { display: block; padding: 8px; }
  .admin-sidebar { height: 100%; }
  .admin-sidebar .session-head { padding: 13px 14px; }
  .admin-content { display: none; height: 100%; padding: 14px; }
  .admin-shell.detail-open .admin-sidebar { display: none; }
  .admin-shell.detail-open .admin-content { display: block; }
  .admin-head { margin-bottom: 14px; gap: 10px; }
  .admin-head h1 { font-size: 20px; }
  .admin-head-main { align-items: center; }
  .admin-head p { margin-top: 2px; }
  .admin-form { padding: 10px; }
  .tenant-list { padding: 6px; }
  .admin-grid { gap: 10px; }
  .admin-list { padding: 6px 14px; }
  .admin-row { gap: 8px; }
  .admin-modal-card { padding: 18px; }
}

@media (max-width: 420px) {
  .topbar { padding: 0 10px; gap: 7px; }
  .brand-text strong { font-size: 14px; }
  .status-pill { padding: 6px 8px; }
  .visitor-hero h1 { font-size: 24px; }
  .visitor-hero p { font-size: 12.5px; }
  .chat-card-header h2 { font-size: 13px; }
  .bubble { max-width: 88%; }
  .session-item { padding: 10px; }
  .admin-row { flex-wrap: wrap; }
  .admin-row .row-actions { width: 100%; justify-content: flex-end; }
  .admin-head .btn { padding: 7px 10px; font-size: 11px; }
  .login-card h1 { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* 永久令牌/Key 展示 */
.secret-line { display: flex; align-items: center; gap: 6px; margin-top: 7px; flex-wrap: wrap; }
.secret-value { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; color: var(--ink-soft); font-size: 11px; font-family: Consolas, monospace; }
.secret-eye, .secret-copy { padding: 4px 8px; min-height: 28px; line-height: 1; font-size: 11px; }
/* 顶部完整 Logo（替代单字图标） */
.brand-logo-link { display: inline-flex; align-items: center; text-decoration: none; flex: 0 0 auto; }
.brand-logo { display: block; height: 40px; width: auto; background: #1f1a16; border-radius: 12px; padding: 3px 9px; box-shadow: 0 5px 14px rgba(31, 26, 22, .16); }
@media (max-width: 760px) {
  .brand-logo { height: 34px; padding: 2px 7px; }
  .topbar .btn { padding: 7px 9px; font-size: 11px; }
}
/* 租户接入方式 */
.admin-access { margin-top: 14px; }
.access-block { padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.access-block:last-child { border-bottom: 0; }
.access-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
.access-head strong { font-size: 12px; }
.access-code { display: block; white-space: pre-wrap; word-break: break-all; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; color: var(--ink-soft); font-size: 11px; font-family: Consolas, monospace; }
/* 未读红点 */
.unread-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 17px; height: 17px; padding: 0 4px; margin-left: auto; border-radius: 999px; background: #e5484d; color: #fff; font-size: 10px; font-weight: 700; line-height: 1; flex: none; box-shadow: 0 0 0 2px var(--surface); }
.session-item .line1 { display: flex; align-items: center; gap: 6px; min-width: 0; }
.session-item .line1 > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 会话结束后继续会话 */
.resume-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 11px 14px; border-bottom: 1px solid var(--line); background: #fbf4e4; color: #6f5a35; font-size: 12px; }
.resume-banner .btn { flex: none; padding: 7px 12px; font-size: 12px; }
@media (max-width: 520px) { .resume-banner { align-items: flex-start; flex-direction: column; } .resume-banner .btn { width: 100%; } }
/* 租户设置与统计 */
.admin-settings, .admin-stats { margin-top: 14px; }
.admin-settings-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; padding: 14px 16px 16px; align-items: end; }
.admin-settings-form > label { display: flex; flex-direction: column; gap: 6px; color: var(--ink-soft); font-size: 12px; }
.admin-settings-form input[type="number"] { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 10px 11px; background: var(--surface); color: var(--ink); font: inherit; }
.admin-settings-form .settings-check { grid-column: 1 / -1; flex-direction: row; align-items: flex-start; gap: 8px; line-height: 1.55; }
.admin-settings-form .settings-check input { margin-top: 3px; }
.admin-settings-form .send-btn { grid-column: 1 / -1; }
.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; padding: 14px 16px 4px; }
.stat-tile { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; }
.stat-tile b { display: block; font-size: 20px; line-height: 1.1; color: var(--ink); }
.stat-tile span { display: block; margin-top: 5px; color: var(--ink-soft); font-size: 11px; }
.stats-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 10px 16px 16px; }
.stats-columns h3 { margin: 4px 0 8px; font-size: 12px; color: var(--ink-soft); }
.stats-list { display: flex; flex-direction: column; gap: 5px; }
.stat-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 9px; border-bottom: 1px solid var(--line-2); font-size: 12px; }
.stat-row span { color: var(--ink-soft); }
.stat-row b { color: var(--ink); white-space: nowrap; }
@media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 620px) { .admin-settings-form { grid-template-columns: 1fr; } .stats-columns { grid-template-columns: 1fr; } .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tenant-admin-token { padding: 0 16px 16px; border-top: 1px solid var(--line-2); margin-top: 4px; padding-top: 12px; }
.tenant-admin-token strong { display: block; font-size: 12px; margin-bottom: 7px; }
/* 租户后台金兔子登录与资料 */
.tenant-oauth-login { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.tenant-oauth-login .send-btn { text-align: center; text-decoration: none; display: flex; align-items: center; justify-content: center; min-height: 46px; }
.tenant-oauth-login .tenant-oauth-qr { text-align: center; text-decoration: none; display: flex; align-items: center; justify-content: center; min-height: 42px; }
.tenant-oauth-login .muted { margin: 2px 0 0; text-align: center; line-height: 1.65; }
.tenant-profile { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tenant-profile img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--gold-soft); flex: none; }
.tenant-profile-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.tenant-profile-text strong { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.tenant-profile-text small { color: var(--ink-soft); font-size: 10px; white-space: nowrap; }
@media (max-width: 620px) { .tenant-profile-text { display: none; } }