/* ═══════════════════════════════════════════════════════════
 * 光湖 · 微调模型内测 · 样式
 * 暗色 (星空) ↔ 亮色 (晨光) 双主题
 * 守护: 铸渊 · ICE-GL-ZY001
 * 版权: 国作登字-2026-A-00037559
 * ═══════════════════════════════════════════════════════════ */

:root {
  --color-accent: #7e8ce0;
  --color-accent-hover: #9aa7f0;
  --color-danger: #e07a8c;
  --radius-md: 10px;
  --radius-lg: 14px;
  --transition: 0.2s ease;
  --max-content: 760px;
}

/* 暗色主题 (默认) */
[data-theme="dark"] {
  --bg-base: #0a0e27;
  --bg-elev: #141936;
  --bg-elev-2: #1d2447;
  --bg-input: rgba(255, 255, 255, 0.06);
  --text-primary: #f4f5fb;
  --text-secondary: #c4cad8;
  --text-muted: #9097ad;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --bubble-user: linear-gradient(135deg, #4a5cb8 0%, #6b7dd0 100%);
  --bubble-user-text: #ffffff;
  --bubble-persona: rgba(255, 255, 255, 0.06);
  --bubble-persona-text: #f4f5fb;
  --bubble-system: rgba(126, 140, 224, 0.14);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4);
  --code-bg: rgba(0, 0, 0, 0.35);
}

/* 亮色主题 */
[data-theme="light"] {
  --bg-base: #f5f7fc;
  --bg-elev: #ffffff;
  --bg-elev-2: #f0f3fa;
  --bg-input: rgba(0, 0, 0, 0.04);
  --text-primary: #14172a;
  --text-secondary: #363c52;
  --text-muted: #5a6378;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.16);
  --bubble-user: linear-gradient(135deg, #5b6dd1 0%, #7e8ce0 100%);
  --bubble-user-text: #ffffff;
  --bubble-persona: #ffffff;
  --bubble-persona-text: #14172a;
  --bubble-system: rgba(126, 140, 224, 0.1);
  --shadow-card: 0 4px 20px rgba(20, 25, 54, 0.08);
  --code-bg: rgba(0, 0, 0, 0.05);
}

/* ─── 基础 ─── */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg-base);
  color: var(--text-primary);
  transition: background var(--transition), color var(--transition);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }

#starfield {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}

/* ─── 主题切换按钮 ─── */
.theme-toggle {
  position: fixed; top: env(safe-area-inset-top, 16px); right: 16px; z-index: 100;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-elev); border: 1px solid var(--border);
  font-size: 18px; box-shadow: var(--shadow-card);
  display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: var(--bg-elev-2); }
[data-theme="dark"] .theme-icon-light,
[data-theme="light"] .theme-icon-dark { display: none; }

/* ─── 登录屏 ─── */
.login-screen {
  position: relative; z-index: 1;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
/* 让 HTML hidden 属性在 .login-screen / .chat-screen 上生效
   （否则 .xxx-screen 的 display:flex 会覆盖 UA 的 [hidden]{display:none}） */
.login-screen[hidden],
.chat-screen[hidden] { display: none; }
.login-card {
  width: 100%; max-width: 440px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 40px 32px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(8px);
}
.login-header { text-align: center; margin-bottom: 24px; }
.login-logo {
  font-size: 40px; line-height: 1;
  background: linear-gradient(135deg, #7e8ce0, #b8c1ee);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 12px;
}
.login-title { margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.login-subtitle { margin: 0; color: var(--text-secondary); font-size: 13px; }
.slots-banner {
  margin-bottom: 24px; padding: 10px 14px;
  background: var(--bubble-system); border-radius: var(--radius-md);
  font-size: 13px; color: var(--text-secondary); text-align: center;
}
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-label { font-size: 13px; color: var(--text-secondary); margin-top: 8px; }
.login-input {
  width: 100%; padding: 12px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none; transition: border-color var(--transition);
}
.login-input:focus { border-color: var(--color-accent); }
.btn-primary, .btn-secondary {
  width: 100%; padding: 12px 16px;
  border-radius: var(--radius-md);
  font-weight: 500; font-size: 15px;
  transition: all var(--transition);
}
.btn-primary {
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover));
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(126, 140, 224, 0.3); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: var(--bg-input); border: 1px solid var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-elev-2); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.login-msg {
  margin: 16px 0 0; min-height: 20px; font-size: 13px; text-align: center;
  color: var(--color-danger);
}
.login-msg.success { color: var(--color-accent); }
.login-footer {
  margin: 24px 0 0; text-align: center;
  font-size: 11px; color: var(--text-muted); line-height: 1.6;
}

/* ─── 聊天屏 ─── */
.chat-screen {
  position: relative; z-index: 1;
  width: 100%; height: 100%;
  display: flex;
}
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 9;
  background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

.sidebar {
  width: 260px; flex-shrink: 0;
  background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  padding-top: max(16px, env(safe-area-inset-top));
}
.sidebar-header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.btn-new-chat {
  flex: 1; padding: 10px 14px;
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover));
  color: #ffffff; border-radius: var(--radius-md); font-weight: 500;
  transition: all var(--transition);
}
.btn-new-chat:hover { transform: translateY(-1px); }
.sidebar-close-mobile { display: none; padding: 8px 12px; font-size: 18px; color: var(--text-secondary); }
.sessions-list {
  flex: 1; overflow-y: auto; padding-right: 4px;
}
.session-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; margin-bottom: 4px;
  border-radius: var(--radius-md); color: var(--text-secondary);
  font-size: 13px; line-height: 1.5;
  cursor: pointer; transition: all var(--transition);
}
.session-item:hover { background: var(--bg-input); color: var(--text-primary); }
.session-item.active { background: var(--bubble-system); color: var(--text-primary); font-weight: 500; }
.session-item-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item-meta { display: block; font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.sidebar-footer {
  border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.user-info { display: flex; align-items: center; gap: 8px; padding: 0 6px; font-size: 12px; }
.user-badge { color: var(--text-secondary); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-badge {
  flex-shrink: 0; padding: 2px 8px; border-radius: 10px;
  background: var(--bubble-system); color: var(--color-accent);
  font-size: 11px; font-weight: 600;
}
.btn-logout {
  padding: 8px 12px; font-size: 13px; color: var(--text-muted);
  border-radius: var(--radius-md); transition: all var(--transition);
}
.btn-logout:hover { background: var(--bg-input); color: var(--color-danger); }

/* ─── 主聊天区 ─── */
.chat-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--bg-base);
  position: relative; /* 锚定左右"即将开放"浮动栏 */
}
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; padding-top: max(14px, env(safe-area-inset-top));
  /* 让标题和气泡共用同一条中线 */
  padding-left: max(20px, calc((100% - var(--max-content)) / 2));
  padding-right: max(20px, calc((100% - var(--max-content)) / 2));
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.sidebar-toggle-mobile { display: none; padding: 6px 10px; font-size: 18px; }
.chat-title-block { flex: 1; min-width: 0; }
.chat-title { margin: 0; font-size: 16px; font-weight: 600; }
.meta-bar { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.chat-body {
  flex: 1; overflow-y: auto;
  padding: 20px; padding-bottom: 12px;
  /* 让对话气泡始终居中限宽（解决"页面太大看着累"）*/
  display: flex; flex-direction: column; align-items: center;
}
.message-row {
  display: flex; margin-bottom: 16px;
  width: 100%; max-width: var(--max-content);
  /* 气泡进入动画（动态 UI）*/
  animation: bubble-in 0.32s ease-out both;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.message-row.user { justify-content: flex-end; }
.message-row.persona, .message-row.system { justify-content: flex-start; }
.bubble {
  max-width: 80%;
  padding: 12px 16px; border-radius: var(--radius-lg);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.bubble.user { background: var(--bubble-user); color: var(--bubble-user-text); border-bottom-right-radius: 4px; box-shadow: 0 4px 14px rgba(74, 92, 184, 0.25); }
.bubble.persona { background: var(--bubble-persona); color: var(--bubble-persona-text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.system { background: var(--bubble-system); color: var(--text-secondary); font-size: 13px; font-style: italic; }

/* ─── Markdown 渲染 ─── */
.bubble.persona h1, .bubble.persona h2, .bubble.persona h3 {
  margin: 16px 0 8px; line-height: 1.3;
}
.bubble.persona h1 { font-size: 1.4em; }
.bubble.persona h2 { font-size: 1.2em; }
.bubble.persona h3 { font-size: 1.05em; }
.bubble.persona p { margin: 8px 0; }
.bubble.persona ul, .bubble.persona ol { margin: 8px 0; padding-left: 24px; }
.bubble.persona li { margin: 4px 0; }
.bubble.persona code {
  background: var(--code-bg); padding: 2px 6px; border-radius: 4px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 0.9em;
}
.bubble.persona pre {
  background: var(--code-bg); padding: 12px; border-radius: var(--radius-md);
  overflow-x: auto; margin: 8px 0;
}
.bubble.persona pre code { background: transparent; padding: 0; }
.bubble.persona table {
  border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 0.92em;
}
.bubble.persona th, .bubble.persona td {
  border: 1px solid var(--border-strong); padding: 6px 10px;
}
.bubble.persona th { background: var(--bg-input); font-weight: 600; }
.bubble.persona blockquote {
  border-left: 3px solid var(--color-accent);
  padding: 4px 12px; margin: 8px 0;
  color: var(--text-secondary); background: var(--bubble-system); border-radius: 4px;
}
.bubble.persona hr { border: none; border-top: 1px solid var(--border-strong); margin: 12px 0; }
.bubble.persona a { color: var(--color-accent); text-decoration: underline; }

.cursor-blink::after {
  content: '▋'; opacity: 0.6;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ─── Composer ─── */
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 12px 20px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  /* 与气泡同一条中线 */
  padding-left: max(20px, calc((100% - var(--max-content)) / 2));
  padding-right: max(20px, calc((100% - var(--max-content)) / 2));
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}
.msg-input {
  flex: 1; min-height: 40px; max-height: 200px;
  padding: 10px 14px; resize: none;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-md); outline: none;
  font-size: 15px; line-height: 1.5;
  transition: border-color var(--transition);
}
.msg-input:focus { border-color: var(--color-accent); }
.btn-send {
  height: 40px; padding: 0 20px;
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover));
  color: #ffffff; border-radius: var(--radius-md); font-weight: 500;
  flex-shrink: 0; transition: all var(--transition);
}
.btn-send:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(126, 140, 224, 0.3); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── 移动端 (<= 768px) ─── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 10;
    width: 80%; max-width: 320px;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-card);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close-mobile { display: inline-flex; }
  .sidebar-toggle-mobile { display: inline-flex; }
  .chat-header {
    padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top));
    padding-left: 14px; padding-right: 14px;
  }
  .chat-body { padding: 14px; }
  .composer {
    padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: 14px; padding-right: 14px;
  }
  .bubble { max-width: 90%; }
  .login-card { padding: 28px 20px; }
}

/* iPhone 长屏 + 安全区 */
@supports (padding: max(0px)) {
  .login-screen { padding-top: max(24px, env(safe-area-inset-top)); padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}

/* 滚动条美化 (仅 Webkit) */
.chat-body::-webkit-scrollbar, .sessions-list::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb, .sessions-list::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 3px;
}
.chat-body::-webkit-scrollbar-thumb:hover, .sessions-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ─── "即将开放功能" 浮动占位栏（>= 1280px 才显示，给居中聊天区两侧填充呼吸感）─── */
.coming-soon {
  display: none;
  position: absolute; top: 90px; bottom: 90px;
  width: 200px;
  padding: 4px;
  pointer-events: none; /* 视觉装饰，不抢交互 */
  z-index: 2;
  overflow-y: auto;
}
.coming-soon-left  { left: 24px; }
.coming-soon-right { right: 24px; }
.coming-soon-title {
  font-size: 12px; letter-spacing: 0.08em;
  color: var(--text-muted); text-transform: none;
  margin-bottom: 14px; padding: 0 4px;
  text-align: center;
}
.coming-soon-card {
  pointer-events: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 12px;
  margin-bottom: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  animation: cs-float 0.6s ease-out both;
  opacity: 0.92;
}
.coming-soon-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: 0 8px 24px rgba(126, 140, 224, 0.18);
  opacity: 1;
}
@keyframes cs-float {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 0.92; transform: translateY(0); }
}
.coming-soon-card .cs-icon { font-size: 22px; line-height: 1; margin-bottom: 6px; }
.coming-soon-card .cs-name {
  font-size: 13px; font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.coming-soon-card .cs-desc {
  font-size: 11.5px; line-height: 1.5;
  color: var(--text-secondary);
}

@media (min-width: 1280px) {
  .coming-soon { display: block; }
}

/* 浮动栏滚动条 */
.coming-soon::-webkit-scrollbar { width: 4px; }
.coming-soon::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 2px;
}
