/* ============================================================
   迅言 · XUNYAN  Design System  v3.0
   ============================================================ */

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

:root {
  --bg-primary:    #f7f8fa;
  --bg-secondary:  #ffffff;
  --bg-tertiary:   #eef0f4;
  --bg-card:       #ffffff;
  --border:        #e2e5ea;
  --border-active: #c4c9d2;

  --text-primary:  #1a1d26;
  --text-secondary:#6b7180;
  --text-muted:    #9aa0b0;

  --accent:        #2563eb;
  --accent-dim:    #1d4ed8;
  --accent-bg:     rgba(37, 99, 235, 0.06);

  --danger:        #dc2626;
  --warning:       #d97706;
  --danger-bg:     rgba(220, 38, 38, 0.06);

  --sidebar-w:     260px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
}

html, body {
  height: 100%;
  height: 100dvh;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  /* 防止 iOS 橡皮筋效果导致的白底 */
  position: fixed;
  width: 100%;
}

/* ── Layout ────────────────────────────────────────────── */
#layout {
  display: flex;
  height: 100%;
  height: 100dvh;
}

/* ── Sidebar ───────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
}
.sidebar-logo { height: 32px; width: auto; }
.sidebar-brand-name { font-size: 16px; font-weight: 700; }
.sidebar-brand-ver {
  font-size: 10px; color: var(--text-muted);
  font-family: var(--font-mono);
}

/* 登录/注册 */
.sidebar-auth {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
}
.btn-auth {
  flex: 1;
  padding: 7px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  gap: 5px;
  transition: background 0.15s;
}
.btn-auth:hover { background: var(--bg-tertiary); }
.btn-auth--primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-auth--primary:hover { background: var(--accent-dim); }

/* 分割线 */
.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 0 16px;
}

/* 历史记录 */
.sidebar-section {
  padding: 12px 12px 8px;
  flex: 1;
  overflow-y: auto;
}
.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 4px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btn-new-chat {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 14px;
  line-height: 1;
  transition: background 0.12s;
}
.btn-new-chat:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.history-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px;
  font-style: italic;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s;
  overflow: hidden;
}
.history-item span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item:hover { background: var(--bg-tertiary); }
.history-item--active { background: var(--accent-bg); color: var(--accent); }
.history-item--active i { color: var(--accent); }
.history-item i { font-size: 14px; color: var(--text-muted); flex-shrink: 0; }
.btn-del {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 11px;
  line-height: 1;
  flex-shrink: 0;
}
.btn-del:hover { color: var(--danger); background: var(--danger-bg); }
.history-item:hover .btn-del { display: block; }

.sidebar-auth--reset-row { padding-top: 0; }
.btn-auth--reset {
  width: 100%;
  color: var(--text-muted);
  font-size: 12px;
}
.btn-auth--reset:hover { color: var(--danger); border-color: rgba(220,38,38,0.3); }

.sidebar-spacer { flex: 1; }

/* 用户区 */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.user-name { font-size: 13px; font-weight: 500; }
.user-plan { font-size: 11px; color: var(--text-muted); }

/* ── Main Area ─────────────────────────────────────────── */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Status Bar ────────────────────────────────────────── */
#status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 14px;
  font-size: 12px;
  font-family: var(--font-mono);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  flex-shrink: 0;
}
#status-bar .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot--ok    { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,0.5); }
.dot--warn  { background: var(--warning); box-shadow: 0 0 6px rgba(217,119,6,0.4); }
.dot--error { background: var(--danger); box-shadow: 0 0 6px rgba(220,38,38,0.4); }
#status-time { margin-left: auto; font-size: 11px; }

#btn-toggle-sidebar {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  padding: 2px 6px; border-radius: 4px;
  font-size: 16px;
  display: none;
}
#btn-toggle-sidebar:hover { background: var(--bg-tertiary); }

/* ── Chat (Canvas) ─────────────────────────────────────── */
#chat-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* 锁定蒙层 */
#lock-warning {
  animation: fadeIn 0.5s ease;
  word-break: break-word;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
#chat-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Text utilities (kept for PHP HTML responses) ──────── */
.text--muted  { color: var(--text-muted); font-size: 12px; }
.text--glitch {
  color: var(--danger);
  animation: glitch-text 3s infinite;
}
.text--warning { color: var(--warning); }

/* ── Input Area ────────────────────────────────────────── */
#input-area {
  padding: 12px 24px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}
#input-area .input-wrapper {
  max-width: 720px;
  margin: 0 auto;
}
.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
}
#user-input::placeholder { color: var(--text-muted); }

#btn-send {
  width: 32px; height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.2s, transform 0.15s;
  flex-shrink: 0;
}
#btn-send:hover { opacity: 0.85; transform: scale(1.05); }
#btn-send i { font-size: 14px; line-height: 1; }

.input-footer {
  margin-top: 8px;
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Animations ────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes glitch-text {
  0%, 90%, 100% { opacity: 1; }
  92% { opacity: 0.3; }
  94% { opacity: 1; color: var(--accent); }
}

/* ── Scrollbar ─────────────────────────────────────────── */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Modal（重置确认）────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-title {
  font-size: 16px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px;
  color: var(--danger);
}
.modal-body { font-size: 14px; color: var(--text-primary); line-height: 1.6; }
.modal-warning {
  font-size: 13px; color: var(--danger); font-weight: 600;
  margin-top: 4px; margin-bottom: 20px;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Toast（登录/注册假弹窗）────────────────────────────── */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  z-index: 100;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
}
.toast i { font-size: 18px; color: var(--accent); }
@keyframes toastIn  { from { opacity: 0; transform: translateX(-50%) translateY(-10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-md);
  }
  #sidebar.open { transform: translateX(0); }

  #btn-toggle-sidebar { display: block; }

  #chat-container { /* canvas handles own layout */ }
  #input-area { padding: 10px 12px 12px; }
  .message__body { max-width: 90%; }
}
