/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f5f5f0;
  --sidebar-bg:  #eeece6;
  --border:      #d9d6cf;
  --text:        #1a1a1a;
  --text-sub:    #6b6b6b;
  --accent:      #c96442;       /* Claude-style orange */
  --user-bg:     #ffffff;
  --assistant-bg:#f5f5f0;
  --input-bg:    #ffffff;
  --shadow:      0 1px 3px rgba(0,0,0,.08);
  --radius:      12px;
  --font:        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body { height: 100%; font-family: var(--font); color: var(--text); background: var(--bg); }

/* ===== Layout ===== */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 12px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.new-chat-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-sub);
  transition: background .15s;
}
.new-chat-btn:hover { background: var(--border); }

/* ===== 应用列表 ===== */
.app-list-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-sub);
  padding: 0 4px;
}

.app-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

.app-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font);
  transition: background .15s;
  width: 100%;
}
.app-item:hover:not(:disabled) { background: rgba(0,0,0,.06); }
.app-item.active {
  background: rgba(201, 100, 66, .12);
  color: var(--accent);
  font-weight: 500;
}
.app-item.active .app-item-icon { color: var(--accent); }
.app-item:disabled { opacity: .45; cursor: not-allowed; }

.app-item-icon {
  flex-shrink: 0;
  color: var(--text-sub);
  display: flex;
}

/* 侧边栏应用头像（小圆形） */
.app-avatar-sm {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.app-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== 侧边栏底部状态 ===== */
.sidebar-footer { margin-top: 0; }

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-sub);
  padding: 4px 4px;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #bbb;
  flex-shrink: 0;
  transition: background .3s;
}
.status-dot.connecting { background: #f0a500; }
.status-dot.connected  { background: #22c55e; }
.status-dot.error      { background: #ef4444; }

/* ===== Main ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.topbar-title {
  font-size: 15px;
  font-weight: 500;
}

/* 顶栏断开按钮 */
.disconnect-btn {
  background: none;
  color: #ef4444;
  border: 1px solid #ef4444;
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.disconnect-btn:hover { background: #ef4444; color: #fff; }

/* 居中大连接按钮 */
.center-connect-btn {
  margin-top: 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 14px 36px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .02em;
  box-shadow: 0 4px 14px rgba(201,100,66,.35);
  transition: opacity .15s, transform .1s;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.center-connect-btn:hover:not(:disabled) { opacity: .9; transform: translateY(-1px); }
.center-connect-btn:active:not(:disabled) { transform: translateY(0); }
.center-connect-btn:disabled { opacity: .4; cursor: default; box-shadow: none; }

/* ===== 呼叫中界面 ===== */
.calling {
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px;
}

.calling-rings {
  position: relative;
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 两个扩散光圈 */
.calling-rings::before,
.calling-rings::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: call-ripple 2s ease-out infinite;
}
.calling-rings::after { animation-delay: .8s; }

@keyframes call-ripple {
  0%   { width: 72px;  height: 72px;  opacity: .7; }
  100% { width: 160px; height: 160px; opacity: 0;  }
}

.calling-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(201,100,66,.4);
  animation: phone-shake 1.6s ease-in-out infinite;
  z-index: 1;
}

/* 头像模式：移除橙色背景，改为头像阴影 */
.calling-icon--avatar {
  background: none;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
}

.calling-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

@keyframes phone-shake {
  0%, 40%, 100% { transform: rotate(0deg); }
  10%  { transform: rotate(-18deg); }
  20%  { transform: rotate(18deg); }
  30%  { transform: rotate(-12deg); }
}

.calling-name {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.calling-status {
  font-size: 13px;
  color: var(--text-sub);
}

.calling-cancel-btn {
  margin-top: 12px;
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(239,68,68,.4);
  transition: opacity .15s, transform .1s;
}
.calling-cancel-btn:hover { opacity: .85; transform: scale(1.08); }

/* ===== Messages ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
}

.welcome {
  margin: auto;
  text-align: center;
  max-width: 400px;
  color: var(--text-sub);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 选中应用后欢迎页显示的大头像 */
.welcome-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
}

.welcome-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.welcome h2 { font-size: 20px; color: var(--text); margin-bottom: 8px; }
.welcome p  { font-size: 14px; line-height: 1.6; }

/* 消息行 */
.message {
  display: flex;
  gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid transparent;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.message.user     { flex-direction: row-reverse; }
.message.assistant{ flex-direction: row; }

/* 头像 */
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
}
.message.user .avatar {
  background: var(--accent);
  color: #fff;
}
.message.assistant .avatar {
  background: #2d2d2d;
  color: #fff;
}

/* 头像图片（AI 智能体） */
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 气泡 */
.bubble {
  max-width: 72%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .bubble {
  background: var(--user-bg);
  box-shadow: var(--shadow);
  border-bottom-right-radius: 4px;
}
.message.assistant .bubble {
  background: var(--assistant-bg);
  border-bottom-left-radius: 4px;
}

/* 打字光标 */
.bubble.typing::after {
  content: "▋";
  display: inline-block;
  animation: blink .8s step-start infinite;
  color: var(--accent);
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* 系统消息 */
.message.system {
  justify-content: center;
}
.message.system .bubble {
  background: none;
  color: var(--text-sub);
  font-size: 12px;
  padding: 4px 0;
  max-width: 100%;
}

/* ===== 录音动画 ===== */
.voice-btn.recording {
  background: rgba(239,68,68,.12);
  color: #ef4444;
}
.voice-btn.recording svg {
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.25); } }

/* ===== Input Area ===== */
.input-area {
  border-top: 1px solid var(--border);
  padding: 16px 24px 20px;
  background: var(--bg);
  flex-shrink: 0;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px 8px 12px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.input-bar:focus-within { border-color: var(--accent); }

.voice-btn, .send-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-sub);
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.voice-btn:hover:not(:disabled), .send-btn:hover:not(:disabled) {
  background: var(--border);
  color: var(--text);
}
.voice-btn:disabled, .send-btn:disabled { opacity: .35; cursor: default; }

.send-btn:not(:disabled) { color: var(--accent); }

.text-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  background: transparent;
  color: var(--text);
  max-height: 160px;
  overflow-y: auto;
}
.text-input::placeholder { color: #bbb; }
.text-input:disabled { cursor: not-allowed; }

.input-hint {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--text-sub);
  text-align: center;
}

/* ===== Scrollbar ===== */
.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== 菜单按钮（桌面隐藏，移动端显示）===== */
.menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  color: var(--text);
  flex-shrink: 0;
  transition: background .15s;
}
.menu-btn:hover { background: var(--border); }

/* ===== 移动端遮罩 ===== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 99;
}
.sidebar-backdrop.open { display: block; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  /* 侧边栏变为滑入式抽屉 */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.18);
  }
  .sidebar.open { transform: translateX(0); }

  .menu-btn { display: flex; }

  .messages { padding: 16px; }
  .input-area { padding: 12px 16px 16px; }
  .bubble { max-width: 88%; }

  /* 顶栏三段式布局 */
  .topbar { padding: 10px 16px; gap: 10px; }
  .topbar-title { flex: 1; text-align: center; font-size: 14px; }
  .disconnect-btn { font-size: 12px; padding: 4px 10px; }
}
