/* 天相 v4 — 主样式 */
* { margin:0; padding:0; box-sizing:border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  background: #f5f5f5; color: #1a1a2e;
  height: 100vh; margin: 0;
}

/* ─── 左右分栏布局（登录/注册时隐藏） ─── */
.app-layout {
  display: flex; height: 100vh; width: 100%;
}

/* ─── 左侧边栏 ─── */
.side-panel {
  width: 260px; min-width: 260px;
  background: #f0f1f3; color: #333;
  display: flex; flex-direction: column;
  border-right: 1px solid #e0e0e0;
}
.side-header {
  padding: 16px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid #e0e0e0;
}
.side-logo { font-size: 18px; font-weight: 700; color: #1a1a2e; letter-spacing: 1px; }
.side-close { background:none; border:none; font-size:16px; cursor:pointer; color:#999; display:none; }
.side-close:hover { color:#333; }
.side-new {
  margin: 10px 12px; padding: 10px 14px;
  background: transparent; color: #555;
  border: 1px solid #d0d0d0; border-radius: 8px;
  font-size: 13px; cursor: pointer; text-align: center; transition: all .15s;
}
.side-new:hover { background: #e5e7ea; border-color: #bbb; color: #1a1a2e; }
.side-list {
  flex: 1; overflow-y: auto; padding: 0 8px;
}
.side-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  font-size: 13px; color: #555; margin: 2px 0;
  display: flex; align-items: center; gap: 8px;
  transition: background .1s; user-select: text;
}
.side-item:hover { background: #e5e7ea; color: #1a1a2e; }
.side-item.active { background: #d0d4da; color: #1a1a2e; font-weight: 500; }
.side-item .preview {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.side-item .del-btn {
  background:none; border:none; color:#aaa; cursor:pointer; font-size:12px; padding:0 4px; visibility:hidden;
}
.side-item:hover .del-btn { visibility:visible; }
.side-item .del-btn:hover { color:#e74c3c; }
.side-footer {
  padding: 12px 16px; border-top: 1px solid #e0e0e0;
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: #888;
}
.side-footer button {
  background:none; border:none; font-size:16px; cursor:pointer; color:#666; padding:2px 4px; border-radius:4px; line-height:1;
}
.side-footer button:hover { background:#e5e7ea; color:#1a1a2e; }
.side-usage { margin-left: auto; }

/* ─── 右侧主区域 ─── */
.main-panel {
  flex: 1; display: none; flex-direction: column;
  height: 100vh; min-width: 0;
}
.main-panel.visible { display: flex; }

.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 24px; border-bottom: 1px solid #e0e0e0;
  background: #fff; flex-shrink: 0;
}
.menu-toggle { background:none; border:none; font-size:18px; cursor:pointer; color:#555; padding:2px 6px; border-radius:4px; display:none; }
.menu-toggle:hover { background:#f0f0f0; }
.chat-title { font-size: 15px; font-weight: 600; color: #1a1a2e; flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

.chat-area {
  flex: 1; overflow-y: auto; padding: 24px 16px 80px;
  display: flex; flex-direction: column; gap: 20px;
  scroll-behavior: smooth;
}

.msg { max-width: 720px; width: 100%; margin: 0 auto; position: relative; }
.msg.user { align-self: flex-end; }
.msg.user + .msg.assistant { margin-top: -4px; }

.msg .bubble {
  padding: 14px 18px; border-radius: 14px;
  line-height: 1.7; font-size: 14px;
}
.msg .del-msg-btn { display: none; }
.msg .time { font-size: 11px; color: #aaa; margin-top: 4px; user-select: none; }
.msg.user .time { text-align: right; }
.msg.user .bubble {
  background: #1a1a2e; color: #f0f0f0;
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
  background: #fff; color: #1a1a2e;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  border-bottom-left-radius: 4px;
}
.msg.assistant .bubble p { margin: 0 0 8px; }
.msg.assistant .bubble p:last-child { margin-bottom: 0; }
.msg.assistant .bubble ul, .msg.assistant .bubble ol { margin: 4px 0 8px 20px; }
.msg.assistant .bubble li { margin-bottom: 4px; }
.msg.assistant .bubble blockquote { border-left: 3px solid #1a1a2e; margin: 8px 0; padding: 4px 12px; color: #555; font-style: italic; }
.msg.assistant .bubble table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13px; }
.msg.assistant .bubble th, .msg.assistant .bubble td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; }
.msg.assistant .bubble th { background: #f0f0f0; font-weight: 600; }
.msg.assistant .bubble code { background: #f0f0f0; padding: 2px 6px; border-radius: 4px; font-size: 13px; font-family: "SF Mono","Menlo",monospace; }
.msg.assistant .bubble pre code { display: block; padding: 12px; overflow-x: auto; background: #f7f7f7; border-radius: 8px; }

.thinking-indicator { display:flex; align-items:center; gap:8px; padding:8px 16px; color:#888; font-size:13px; }
.thinking-dots { display:flex; gap:3px; }
.thinking-dots span { width:6px; height:6px; background:#888; border-radius:50%; animation:dot-pulse 1.4s infinite ease-in-out both; }
.thinking-dots span:nth-child(1) { animation-delay:-0.32s; }
.thinking-dots span:nth-child(2) { animation-delay:-0.16s; }
@keyframes dot-pulse { 0%,80%,100%{transform:scale(0)} 40%{transform:scale(1)} }

.input-area { flex-shrink:0; border-top:1px solid #e0e0e0; padding:12px 24px; background:#fff; }
.input-row { max-width:720px; margin:0 auto; display:flex; gap:8px; align-items:flex-end; }
.input-row textarea {
  flex:1; padding:10px 14px; border:1px solid #ddd; border-radius:10px;
  font-size:14px; outline:none; transition:border-color .2s;
  font-family:inherit; resize:none; min-height:42px; max-height:120px; line-height:1.4;
}
.input-row textarea:focus { border-color:#1a1a2e; }
.input-row button {
  padding:10px 20px; background:#1a1a2e; color:#fff;
  border:none; border-radius:10px; font-size:14px; cursor:pointer;
  transition:opacity .2s; white-space:nowrap;
}
.input-row button:disabled { opacity:.5; cursor:not-allowed; }

/* ─── 注册/登录面板 ─── */
.register-area {
  max-width: 400px; margin: 60px auto; padding: 32px;
  background: #fff; border-radius: 14px; box-shadow: 0 2px 16px rgba(0,0,0,.06);
}
.register-area h2 { font-size: 20px; margin-bottom: 20px; }
.register-area .field { margin-bottom: 14px; }
.register-area label { display: block; font-size: 13px; color: #666; margin-bottom: 4px; }
.register-area input, .register-area select {
  width: 100%; padding: 10px 12px; border: 1px solid #ddd;
  border-radius: 8px; font-size: 14px; outline: none; transition: border-color .2s;
}
.register-area input:focus { border-color: #1a1a2e; }
.register-area button {
  width: 100%; padding: 12px; background: #1a1a2e; color: #fff;
  border: none; border-radius: 8px; font-size: 14px; cursor: pointer;
  margin-top: 8px; transition: opacity .2s;
}
.register-area button:hover { opacity: .9; }

.error-msg { color: #d32f2f; font-size: 13px; margin-top: 8px; display: none; }
.hidden { display: none !important; }

/* ─── 上传弹窗 ─── */
.upload-overlay { position:fixed; inset:0; background:rgba(0,0,0,.45); display:none; align-items:center; justify-content:center; z-index:1000; }
.upload-modal { background:#fff; border-radius:14px; padding:24px; max-width:500px; width:90%; box-shadow:0 8px 32px rgba(0,0,0,.18); }

/* ─── 个人信息弹窗 ─── */
.profile-overlay { position:fixed; inset:0; background:rgba(0,0,0,.45); display:flex; align-items:center; justify-content:center; z-index:2000; animation:fadeIn .2s ease; }
.profile-modal { background:#fff; border-radius:14px; max-width:420px; width:90%; max-height:85vh; overflow-y:auto; box-shadow:0 8px 32px rgba(0,0,0,.18); animation:slideUp .25s ease; padding:24px; position:relative; }
.profile-modal h2 { font-size:18px; margin-bottom:16px; }
.profile-modal .close-btn { position:absolute; top:14px; right:16px; font-size:20px; color:#999; cursor:pointer; background:none; border:none; line-height:1; }
.profile-modal .field { margin-bottom:10px; }
.profile-modal label { display:block; font-size:12px; color:#666; margin-bottom:3px; }
.profile-modal input, .profile-modal select { width:100%; padding:8px 10px; border:1px solid #ddd; border-radius:6px; font-size:14px; box-sizing:border-box; }
.profile-modal .row2 { display:flex; gap:10px; }
.profile-modal .row2 .field { flex:1; }
.profile-modal .save-btn { width:100%; padding:10px; background:#1a1a2e; color:#fff; border:none; border-radius:8px; font-size:14px; cursor:pointer; margin-top:12px; }
.profile-modal .save-btn:disabled { opacity:.5; cursor:not-allowed; }
.profile-modal .profile-error { color:#d32f2f; font-size:13px; margin-top:8px; display:none; }
.profile-section { background:#f8f9fa; border-radius:10px; padding:16px; margin-bottom:16px; }
.profile-section-title { font-size:14px; font-weight:600; color:#1a1a2e; margin-bottom:12px; }
.profile-modal textarea { width:100%; padding:8px 10px; border:1px solid #ddd; border-radius:6px; font-size:14px; box-sizing:border-box; resize:vertical; font-family:inherit; }
@keyframes slideUp { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:translateY(0); } }

/* ─── 移动端 ─── */
@media (max-width: 768px) {
  .side-panel {
    position: fixed; left: -280px; top: 0; bottom: 0; z-index: 500;
    transition: left .2s ease; width: 280px;
  }
  .side-panel.open { left: 0; box-shadow: 4px 0 20px rgba(0,0,0,.15); }
  .side-close { display: block; }
  .menu-toggle { display: block; }
  .main-panel { margin-left: 0; }
  .chat-area { padding: 16px 12px 80px; }
  .msg { max-width: 100%; }
  .msg .bubble { padding: 12px 14px; font-size: 14px; }
  .input-area { padding: 10px 12px; }
  .input-row textarea { font-size: 16px; min-height: 44px; }
  .register-area { margin: 20px auto; padding: 16px; max-width: 100%; border-radius: 0; box-shadow: none; }
  #onboardingPanel { margin: 10px; padding: 16px; max-width: 100%; }
  .profile-modal { max-width: 100% !important; width: 100% !important; border-radius: 0; max-height: 100vh; }
}

/* ─── TOAST ─── */
.toast { position:fixed; bottom:24px; right:24px; background:#1a1a2e; color:#fff; padding:12px 20px; border-radius:8px; font-size:13px; z-index:999; animation:fadeIn .3s; }
@keyframes fadeIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }

/* ─── 覆盖旧样式 ─── */
.sidebar-toggle, .sidebar-overlay, .sidebar { display: none; }

/* ─── Onboarding 过渡层 ─── */
.ob-transition {
  text-align: center; padding: 60px 20px;
  animation: fadeIn .4s ease;
}
.ob-transition .ob-icon {
  font-size: 48px; margin-bottom: 20px;
  animation: obPulse 2s ease-in-out infinite;
}
.ob-transition h2 {
  font-size: 20px; margin-bottom: 8px; color: #1a1a2e;
}
.ob-transition .ob-sub {
  font-size: 14px; color: #888; margin-bottom: 24px;
}
.ob-transition .ob-bar-track {
  width: 220px; height: 4px; background: #e8e8e8;
  border-radius: 2px; margin: 0 auto; overflow: hidden;
}
.ob-transition .ob-bar-fill {
  height: 100%; background: #1a1a2e; border-radius: 2px;
  animation: obProgress 12s ease-out forwards;
  width: 0%;
}
@keyframes obPulse {
  0%,100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: .7; }
}
@keyframes obProgress {
  0%   { width: 0%; }
  10%  { width: 18%; }
  30%  { width: 35%; }
  55%  { width: 55%; }
  75%  { width: 72%; }
  90%  { width: 88%; }
  100% { width: 95%; }
}
