/* ============================================================
   索尼DI智能说明书 — 站内聊天界面
   与 assets/css/theme-v2.css 同一套浅色蓝紫体系
   ============================================================ */

:root {
  --c-bg: #F7F8FE;
  --c-surface: #FFFFFF;
  --c-ink: #232A47;
  --c-ink-2: #5E6685;
  --c-ink-3: #8A90A8;
  --c-line: #E4E7F6;
  --c-primary: #5F6FE8;
  --c-primary-hover: #4E5EDB;
  --c-primary-soft: #EEF0FE;
  --c-danger: #D9534F;
  --c-success: #2F9E6F;
  --c-shadow: 0 2px 6px rgba(124, 100, 224, .10);
  --c-shadow-lg: 0 10px 30px rgba(124, 100, 224, .16);
  --c-radius: 16px;
  --c-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --c-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--c-font);
  color: var(--c-ink);
  background:
    radial-gradient(900px 420px at 12% -8%, rgba(136, 173, 239, .16), transparent 62%),
    radial-gradient(820px 400px at 92% -10%, rgba(146, 139, 233, .14), transparent 62%),
    var(--c-bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- 框架 ---------- */
.app {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  height: 100dvh;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(255, 255, 255, .72);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--c-line);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #88ADEF, #928BE9);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  box-shadow: var(--c-shadow);
}

.brand-text { line-height: 1.25; }
.brand-text b { display: block; font-size: 14px; }
.brand-text span { font-size: 11px; color: var(--c-ink-3); }

.new-chat {
  margin: 6px 14px 10px;
  padding: 10px 14px;
  border: 1px dashed var(--c-line);
  border-radius: 12px;
  background: #fff;
  color: var(--c-ink);
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: .18s;
}

.new-chat:hover {
  border-color: var(--c-primary);
  color: var(--c-primary);
  background: var(--c-primary-soft);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
  min-height: 0;
}

.chat-list-empty {
  padding: 18px 12px;
  font-size: 12px;
  color: var(--c-ink-3);
  text-align: center;
  line-height: 1.6;
}

.chat-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  margin: 2px 0;
  border-radius: 10px;
  font-size: 13px;
  color: var(--c-ink-2);
  cursor: pointer;
  transition: background .15s, color .15s;
}

.chat-item:hover { background: rgba(95, 111, 232, .07); color: var(--c-ink); }

.chat-item.active {
  background: #fff;
  color: var(--c-ink);
  font-weight: 600;
  box-shadow: var(--c-shadow);
}

.chat-item .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item .del {
  border: 0;
  background: transparent;
  color: var(--c-ink-3);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 6px;
  opacity: 0;
  transition: .15s;
}

.chat-item:hover .del { opacity: 1; }
.chat-item .del:hover { color: var(--c-danger); background: rgba(217, 83, 79, .1); }

.sidebar-foot {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--c-line);
  font-size: 11px;
  color: var(--c-ink-3);
  line-height: 1.6;
}

/* ---------- 主区 ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--c-line);
  background: rgba(255, 255, 255, .66);
  backdrop-filter: blur(10px);
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--c-line);
  border-radius: 10px;
  background: #fff;
  color: var(--c-ink-2);
  cursor: pointer;
  font-size: 15px;
  transition: .15s;
}

.icon-btn:hover { color: var(--c-primary); border-color: var(--c-primary); }
.icon-btn.menu { display: none; }

.agent-id { display: flex; align-items: center; gap: 10px; min-width: 0; }

.agent-avatar {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, #88ADEF, #928BE9);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  flex: none;
}

.agent-meta { min-width: 0; }
.agent-meta b { display: block; font-size: 14px; }
.agent-meta span {
  font-size: 11.5px;
  color: var(--c-ink-3);
  display: flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-success);
  display: inline-block;
}

.dot.busy { background: #E0A32E; animation: pulse 1.2s infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.topbar-spacer { flex: 1; }

.top-link {
  font-size: 12.5px;
  color: var(--c-ink-2);
  text-decoration: none;
  padding: 7px 11px;
  border-radius: 9px;
  transition: .15s;
}

.top-link:hover { color: var(--c-primary); background: var(--c-primary-soft); }

/* ---------- 消息区 ---------- */
.scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 26px 20px 8px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.thread {
  width: 100%;
  max-width: 860px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* 空态 */
.empty {
  width: 100%;
  max-width: 720px;
  margin-block: auto;
  text-align: center;
  padding: 0 8px;
}

.empty .logo {
  width: 62px;
  height: 62px;
  border-radius: 18px;
  margin: 0 auto 18px;
  background: linear-gradient(135deg, #88ADEF, #928BE9);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 700;
  box-shadow: var(--c-shadow-lg);
}

.empty h1 { font-size: 22px; margin: 0 0 8px; letter-spacing: .2px; }
.empty p { margin: 0 auto 22px; color: var(--c-ink-2); font-size: 13.5px; line-height: 1.7; max-width: 520px; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.chip {
  padding: 10px 14px;
  border: 1px solid var(--c-line);
  background: #fff;
  border-radius: 12px;
  font-size: 13px;
  color: var(--c-ink-2);
  cursor: pointer;
  transition: .16s;
  box-shadow: var(--c-shadow);
}

.chip:hover { border-color: var(--c-primary); color: var(--c-primary); transform: translateY(-1px); }

/* 单条消息 */
.msg { display: flex; gap: 12px; align-items: flex-start; }

.msg .avatar {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.msg.assistant .avatar { background: linear-gradient(135deg, #88ADEF, #928BE9); }
.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: #C9CEE8; color: #4A5378; }

.bubble {
  min-width: 0;
  max-width: 100%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.78;
  word-break: break-word;
}

.msg.assistant .bubble {
  background: #fff;
  border: 1px solid var(--c-line);
  box-shadow: var(--c-shadow);
  border-top-left-radius: 6px;
  flex: 1;
}

.msg.user .bubble {
  background: var(--c-primary);
  color: #fff;
  border-top-right-radius: 6px;
  max-width: 78%;
  white-space: pre-wrap;
  box-shadow: 0 4px 14px rgba(95, 111, 232, .28);
}

.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0 10px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 14px 0 8px;
  font-size: 15.5px;
  line-height: 1.5;
}
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child { margin-top: 2px; }
.bubble code {
  font-family: var(--c-mono);
  font-size: 12.5px;
  background: #F1F3FD;
  border: 1px solid var(--c-line);
  border-radius: 5px;
  padding: 1px 5px;
}
.bubble pre {
  background: #1E2438;
  color: #E6E9F5;
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 12.5px;
  line-height: 1.6;
}
.bubble pre code { background: transparent; border: 0; padding: 0; color: inherit; }
.bubble table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid var(--c-line); padding: 6px 10px; text-align: left; }
.bubble th { background: #F7F8FE; font-weight: 600; }
.bubble a { color: var(--c-primary); }
.bubble img { max-width: 100%; border-radius: 10px; }
.bubble blockquote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--c-line);
  color: var(--c-ink-2);
}

/* 打字光标 */
.cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  background: var(--c-primary);
  border-radius: 1px;
  vertical-align: -2px;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* 状态行 */
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--c-ink-3);
  margin-top: 8px;
}

.status .dots { display: inline-flex; gap: 3px; }
.status .dots i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--c-primary); opacity: .45;
  animation: bounce 1.2s infinite;
}
.status .dots i:nth-child(2) { animation-delay: .15s; }
.status .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-3px); opacity: 1; } }

/* 参考来源 */
.refs { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--c-line); }
.refs-title { font-size: 11.5px; color: var(--c-ink-3); margin-bottom: 6px; }
.ref-item {
  display: flex;
  gap: 6px;
  font-size: 12px;
  color: var(--c-ink-2);
  padding: 3px 0;
  line-height: 1.5;
}
.ref-item a { color: var(--c-primary); text-decoration: none; }
.ref-item a:hover { text-decoration: underline; }
.ref-idx {
  flex: none;
  width: 16px; height: 16px;
  border-radius: 4px;
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-size: 10px;
  display: grid;
  place-items: center;
  margin-top: 1px;
}

/* 消息操作 */
.actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity .15s;
}
.msg.assistant:hover .actions { opacity: 1; }
.act {
  border: 1px solid transparent;
  background: transparent;
  color: var(--c-ink-3);
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.act:hover { color: var(--c-primary); background: var(--c-primary-soft); }

/* 错误 */
.err {
  border: 1px solid rgba(217, 83, 79, .35);
  background: rgba(217, 83, 79, .06);
  color: #A33;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.6;
}

/* ---------- 输入区 ---------- */
.composer-wrap {
  padding: 10px 20px 18px;
  background: linear-gradient(to top, var(--c-bg) 55%, transparent);
}

.composer {
  max-width: 860px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--c-line);
  border-radius: 16px;
  box-shadow: var(--c-shadow-lg);
  padding: 8px 8px 8px 14px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  transition: border-color .15s, box-shadow .15s;
}

.composer:focus-within {
  border-color: rgba(95, 111, 232, .55);
  box-shadow: 0 8px 26px rgba(95, 111, 232, .18);
}

.composer textarea {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  font: inherit;
  font-size: 14.5px;
  line-height: 1.6;
  max-height: 180px;
  min-height: 26px;
  padding: 6px 0;
  background: transparent;
  color: var(--c-ink);
}

.composer textarea::placeholder { color: var(--c-ink-3); }

.send {
  width: 38px;
  height: 38px;
  flex: none;
  border: 0;
  border-radius: 11px;
  background: var(--c-primary);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: .15s;
}

.send:hover:not(:disabled) { background: var(--c-primary-hover); }
.send:disabled { background: #C9CEE8; cursor: not-allowed; }

.hint {
  max-width: 860px;
  margin: 8px auto 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 10px;
  font-size: 11px;
  color: var(--c-ink-3);
}

/* ---------- 移动端 ---------- */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(35, 42, 71, .35);
  z-index: 20;
  backdrop-filter: blur(2px);
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: 280px;
    transform: translateX(-102%);
    transition: transform .22s ease;
    background: #fff;
  }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .backdrop { display: block; }
  .icon-btn.menu { display: grid; }
  .scroll { padding: 18px 14px 6px; }
  .composer-wrap { padding: 8px 14px 14px; }
  .msg.user .bubble { max-width: 88%; }
  .empty h1 { font-size: 19px; }
  .top-link { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
