:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6e9f0;
  --text: #1a1f2e;
  --muted: #6b7488;
  --primary: #4f46e5;
  --primary-soft: #eef0ff;
  --danger: #e11d48;
  --ok: #10b981;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 25, 45, .04), 0 8px 24px rgba(20, 25, 45, .06);
}

/* 暗色主题 */
[data-theme="dark"] {
  --bg: #0e1016;
  --surface: #171a23;
  --surface-2: #1d212c;
  --border: #2a2f3d;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --primary: #6366f1;
  --primary-soft: #232642;
  --danger: #f43f5e;
  --ok: #34d399;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 15% -10%, #e9edff 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .3s ease, color .3s ease;
}
[data-theme="dark"] body,
[data-theme="dark"] .login-mask {
  background: radial-gradient(1000px 520px at 15% -10%, #1d2140 0%, transparent 60%), var(--bg);
}
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select { color-scheme: dark; }
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* 登录 */
.login-mask {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: radial-gradient(900px 500px at 50% 0%, #e9edff, #f4f6fb 70%);
}
.login-card {
  width: 340px; padding: 34px 30px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow);
  animation: pop .35s cubic-bezier(.16,1,.3,1);
}
.login-logo { font-size: 38px; }
.login-card h1 { margin: 8px 0 4px; font-size: 19px; }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.login-card input {
  width: 100%; padding: 11px 13px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  outline: none; transition: .2s;
}
.login-card input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-soft); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

/* 布局 */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 22px; height: 60px; flex: none;
  background: rgba(255,255,255,.82); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px rgba(16,185,129,.15); }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  padding: 7px 15px; border: 0; border-radius: 999px; cursor: pointer;
  background: transparent; color: var(--muted);
  transition: .18s;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--primary); color: #fff; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 5px;
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 11px; font-style: normal; line-height: 18px; text-align: center;
}
.main { flex: 1; overflow: hidden; }
.panel { display: none; height: 100%; }
.panel.active { display: flex; }

/* 按钮 */
.btn {
  border: 1px solid var(--border); background: var(--surface);
  padding: 8px 15px; border-radius: 10px; cursor: pointer;
  transition: .18s cubic-bezier(.16,1,.3,1); white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 11px; font-size: 13px; }

/* 自动消息面板 */
#panel-flow { flex-direction: column; overflow: auto; padding: 24px; gap: 16px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.panel-head h2 { margin: 0 0 4px; font-size: 18px; }
.panel-head p { margin: 0; color: var(--muted); font-size: 13px; max-width: 640px; }
.steps { display: flex; flex-direction: column; gap: 14px; }

.step {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
  transition: transform .22s cubic-bezier(.16,1,.3,1), box-shadow .22s;
}
.step::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--primary), #06b6d4);
  opacity: 0; transition: .25s;
}
.step:hover::before { opacity: 1; }
.step:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(20,25,45,.1); }
.step.off { opacity: .55; }
[data-theme="dark"] .step:hover { box-shadow: 0 10px 26px rgba(0,0,0,.4); }

/* 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(130,140,160,.32); border-radius: 9px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(130,140,160,.55); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* Toast 玻璃感 */
.toast { backdrop-filter: blur(8px); box-shadow: 0 8px 24px rgba(0,0,0,.22); }

/* 卡片底部：保存状态 + 保存按钮 */
.step-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
}
.save-state { font-size: 12px; color: var(--muted); }
.save-state.dirty { color: #f59e0b; }
.save-state.dirty::before { content: '● '; }

.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.step-no {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 600;
}
.step-head .spacer { margin-left: auto; }
.step-tip { font-size: 12px; color: var(--muted); }
.switch { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; cursor: pointer; }
.switch input { accent-color: var(--primary); width: 16px; height: 16px; }

.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 5px; font-size: 12px; color: var(--muted); }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2); outline: none; transition: .18s; resize: vertical;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-soft);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btns-box { border-top: 1px dashed var(--border); padding-top: 12px; margin-top: 4px; }
.btns-box h4 { margin: 0 0 8px; font-size: 13px; }
.btn-row { display: grid; grid-template-columns: 1.1fr .8fr 1.4fr 60px auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.btn-row input, .btn-row select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); outline: none; min-width: 0;
}
.icon-btn {
  width: 30px; height: 30px; display: grid; place-items: center;
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; cursor: pointer;
  color: var(--muted); transition: .16s;
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }
.empty { color: var(--muted); padding: 40px; text-align: center; }

/* 上传网格（可多选，混排相册） */
.media-field { margin-bottom: 12px; }
.media-label { display: block; margin-bottom: 9px; font-size: 12px; color: var(--muted); }
.media-grid {
  display: flex; flex-wrap: wrap; gap: 10px;
  transition: opacity .2s;
}
.media-grid.loading { opacity: .55; pointer-events: none; }

.dz {
  position: relative;
  width: 116px; height: 116px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface-2); overflow: hidden;
  animation: pop .22s ease;
}
.dz-thumb { width: 100%; height: 100%; object-fit: cover; background: #0b0d12; display: block; }
.dz-file { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 8px; }
.dz-file audio { width: 98px; }

/* 末尾的「+」方块 */
.dz-add {
  border: 2px dashed var(--border); cursor: pointer;
  transition: .22s cubic-bezier(.16,1,.3,1);
}
.dz-add:hover { border-color: var(--primary); background: var(--primary-soft); transform: translateY(-2px); box-shadow: 0 8px 20px rgba(79,70,229,.14); }
.media-grid.over .dz-add { border-color: var(--primary); background: var(--primary-soft); transform: scale(1.05); }
.dz-plus {
  font-size: 32px; line-height: 1; font-weight: 300; color: var(--primary);
  transition: transform .22s cubic-bezier(.16,1,.3,1);
}
.dz-add:hover .dz-plus { transform: rotate(90deg) scale(1.12); }
.dz-text { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* 移除按钮 */
.dz-x {
  position: absolute; top: 5px; right: 5px;
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  border: 0; background: rgba(15,17,23,.62); color: #fff;
  font-size: 12px; cursor: pointer; backdrop-filter: blur(4px);
  transition: .18s;
}
.dz-x:hover { background: var(--danger); transform: scale(1.08); }

/* 会话面板 */
#panel-chat { height: 100%; }
.user-list {
  width: 268px; flex: none; border-right: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column;
}
.search { padding: 12px; border-bottom: 1px solid var(--border); }
.search input {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--surface-2); outline: none;
}
.users { overflow: auto; flex: 1; }
.user-item {
  display: flex; gap: 10px; padding: 11px 13px; cursor: pointer;
  border-bottom: 1px solid #f1f3f8; transition: .15s;
}
.user-item:hover { background: var(--surface-2); }
.user-item.active { background: var(--primary-soft); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #06b6d4); color: #fff; font-weight: 600; font-size: 13px;
}
.user-item .u-info { min-width: 0; flex: 1; }
.user-item .u-name { font-weight: 500; display: flex; gap: 6px; align-items: center; }
.user-item .u-last { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }

.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.chat-head strong { display: block; }
.chat-head small { color: var(--muted); font-size: 12px; }
.messages { flex: 1; overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); }
.bubble { max-width: 68%; padding: 10px 14px; border-radius: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; animation: pop .22s ease; }
.bubble.in { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble .meta { display: block; margin-top: 5px; font-size: 11px; opacity: .6; }
.b-media { max-width: 100%; max-height: 240px; border-radius: 10px; display: block; margin-bottom: 6px; }
.b-audio { width: 240px; max-width: 100%; margin-bottom: 6px; }
.b-filelink { display: inline-block; margin-bottom: 6px; color: inherit; }
.b-fallback { opacity: .75; }
.b-text { white-space: pre-wrap; word-break: break-word; }

/* 附件条 */
.attach-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-top: 1px solid var(--border);
  background: var(--primary-soft); font-size: 13px;
}
.attach-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-bar select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

.composer { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); align-items: flex-end; }
.composer textarea {
  flex: 1; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2); outline: none; resize: none; min-height: 44px;
}
.composer textarea:focus { border-color: var(--primary); background: #fff; }

/* 设置 */
#panel-settings { flex-direction: column; gap: 16px; overflow: auto; padding: 24px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); max-width: 780px;
}
.card h3 { margin: 0 0 6px; font-size: 15px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: flex-start; }
.row input, .row textarea {
  flex: 1; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2); outline: none; resize: vertical;
}
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.tips li { margin-bottom: 5px; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font-size: 12px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translate(-50%, 20px);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .25s; z-index: 99;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .grid2 { grid-template-columns: 1fr; }
  .user-list { width: 200px; }
  .btn-row { grid-template-columns: 1fr 1fr; }
}
