/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #1a1a2e; --bg2: #16213e; --bg3: #0f3460;
  --surface: #222244; --surface2: #2a2a50;
  --text: #e8e8f0; --text2: #a0a0c0;
  --accent: #7c5cfc; --accent2: #5a3fd6;
  --user-msg: #2a2a50; --ai-msg: #1e1e3a;
  --radius: 12px; --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --sidebar-w: 220px;
}
html, body { height: 100%; width: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}

/* ===== Layout ===== */
#app { display: flex; height: 100vh; width: 100vw; }

/* ===== Sidebar ===== */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg2); display: flex; flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.05);
}
.logo { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.logo-icon { font-size: 22px; }
.logo-text { font-size: 16px; font-weight: 700; color: var(--text); letter-spacing: 1px; }
#nav-scenes { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 16px; border: none; background: transparent;
  color: var(--text2); font-size: 14px; cursor: pointer;
  transition: all 0.15s; text-align: left;
}
.nav-item:hover { background: rgba(124,92,252,0.08); color: var(--text); }
.nav-item.active { background: rgba(124,92,252,0.15); color: #fff; border-left: 3px solid var(--accent); }
.nav-icon { font-size: 16px; width: 22px; text-align: center; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.05); }
.model-badge { font-size: 11px; color: var(--text2); padding: 4px 8px; background: rgba(255,255,255,0.05); border-radius: 6px; display: inline-block; }
.nav-group-label { font-size: 10px; color: #666; padding: 12px 16px 4px; text-transform: uppercase; letter-spacing: 1px; }

/* ===== Login Page ===== */
#login-page { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; background: var(--bg); }
#login-page.hidden { display: none; }
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-box { background: var(--bg2); border-radius: 16px; padding: 40px 32px; text-align: center; box-shadow: 0 8px 40px rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.05); }
.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-title { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: var(--text2); margin-bottom: 28px; }
.login-input-group { margin-bottom: 16px; }
.login-input-group input { width: 100%; padding: 12px 16px; background: var(--surface); border: 1px solid rgba(255,255,255,0.1); border-radius: 10px; color: var(--text); font-size: 16px; outline: none; box-sizing: border-box; transition: 0.15s; }
.login-input-group input:focus { border-color: var(--accent); }
.login-input-group input::placeholder { color: #666; }
#login-error { color: #ff4757; font-size: 13px; margin-bottom: 12px; }
#login-error.hidden { display: none; }
#login-btn { width: 100%; padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: 10px; font-size: 16px; cursor: pointer; transition: 0.15s; }
#login-btn:hover { background: var(--accent2); }
#btn-logout { background: none; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; transition: 0.15s; }
#btn-logout:hover { background: rgba(255,255,255,0.05); color: #ff6b81; }

/* ===== Main ===== */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; background: var(--bg2);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
#menu-toggle { display: none; background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; }
#scene-title { display: flex; align-items: center; gap: 10px; flex: 1; }
#scene-icon { font-size: 20px; }
#scene-name { font-size: 16px; font-weight: 600; }
#header-actions { display: flex; gap: 8px; }
#header-actions button { background: none; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; transition: 0.15s; }
#header-actions button:hover { background: rgba(255,255,255,0.05); color: var(--text); }

/* ===== Chat Area ===== */
#chat-area { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; }
#messages { max-width: 800px; width: 100%; margin: 0 auto; }
.message { margin-bottom: 16px; display: flex; }
.message.user { justify-content: flex-end; }
.msg-content {
  max-width: 80%; padding: 12px 16px; border-radius: var(--radius);
  line-height: 1.7; word-wrap: break-word; white-space: pre-wrap;
}
.message.user .msg-content {
  background: var(--accent); color: #fff;
  border-bottom-right-radius: 4px;
}
.message.ai .msg-content {
  background: var(--surface); color: var(--text);
  border-bottom-left-radius: 4px;
}
.message.system .msg-content {
  background: transparent; color: var(--text2); text-align: center;
  max-width: 100%; font-size: 14px;
}
.message.system .msg-content p { margin-bottom: 4px; }

/* Code blocks in messages */
.msg-content pre { background: #111; padding: 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0; font-size: 13px; }
.msg-content code { background: rgba(255,255,255,0.07); padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.msg-content pre code { background: none; padding: 0; }

/* Loading */
#loading-indicator { display: flex; align-items: center; gap: 10px; padding: 8px 0; margin: 0 auto; max-width: 800px; width: 100%; color: var(--text2); font-size: 14px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--text2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Input Area ===== */
#input-area { border-top: 1px solid rgba(255,255,255,0.05); padding: 12px 20px 16px; background: var(--bg2); }
#custom-inputs.hidden { display: none; }
#input-panel { margin-bottom: 8px; }
#input-row { display: flex; align-items: flex-end; gap: 8px; max-width: 800px; margin: 0 auto; }
#input-wrapper { flex: 1; background: var(--surface); border-radius: var(--radius); border: 1px solid rgba(255,255,255,0.08); transition: 0.15s; }
#input-wrapper:focus-within { border-color: var(--accent); }
#chat-input {
  width: 100%; padding: 10px 14px; border: none; background: transparent;
  color: var(--text); font-size: 15px; line-height: 1.5; resize: none;
  font-family: inherit; outline: none; max-height: 150px;
}
#chat-input::placeholder { color: var(--text2); }
#btn-upload { background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; padding: 6px; border-radius: 6px; }
#btn-upload:hover { background: rgba(255,255,255,0.05); }
#btn-send { padding: 8px 20px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: 14px; cursor: pointer; transition: 0.15s; white-space: nowrap; }
#btn-send:hover { background: var(--accent2); }
#btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-content { position: relative; background: var(--bg2); border-radius: var(--radius); width: 90%; max-width: 420px; box-shadow: var(--shadow); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.modal-header h2 { font-size: 16px; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 18px; cursor: pointer; }
.modal-body { padding: 20px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.form-group input[type="text"], .form-group select { width: 100%; padding: 8px 12px; background: var(--surface); border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; color: var(--text); font-size: 14px; }
.form-group small { display: block; font-size: 11px; color: #888; margin-top: 4px; }
.slider-group { display: flex; align-items: center; gap: 12px; }
.slider-group input[type="range"] { flex: 1; accent-color: var(--accent); }
.slider-group span { min-width: 30px; text-align: center; font-size: 14px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid rgba(255,255,255,0.05); display: flex; justify-content: flex-end; }
.btn-primary { padding: 8px 24px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 14px; cursor: pointer; }
.btn-primary:hover { background: var(--accent2); }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  #sidebar { position: fixed; left: -250px; top: 0; bottom: 0; z-index: 500; width: 250px; min-width: 250px; transition: left 0.2s; }
  #sidebar.open { left: 0; box-shadow: 4px 0 20px rgba(0,0,0,0.5); }
  #menu-toggle { display: block !important; }
  #menu-toggle.open { color: var(--accent); }
  .logo { padding: 14px 14px; }
  .nav-item { padding: 12px 14px; font-size: 15px; }
  #scene-icon { font-size: 18px; }
  #scene-name { font-size: 15px; }
  #header { padding: 10px 12px; gap: 8px; }
  #header-actions button { font-size: 16px; padding: 4px 6px; }
  .msg-content { max-width: 92%; font-size: 14px; padding: 10px 14px; }
  #chat-area { padding: 10px 10px; }
  #input-area { padding: 8px 10px 12px; }
  #input-row { padding: 0; }
  #chat-input { font-size: 16px; padding: 10px 12px; }  /* 16px防止iOS缩放 */
  #btn-send { padding: 10px 16px; font-size: 15px; }
  
  /* 登录页适配 */
  .login-box { padding: 32px 20px; }
  .login-title { font-size: 20px; }
  .login-input-group input { font-size: 16px; }
  
  /* 弹窗适配 */
  .modal-content { max-width: 90%; }
}
