/* ══════════════════════════════════════════════════════
   AI 智能助手平台 — Enterprise Dark Theme
   ══════════════════════════════════════════════════════ */

/* ── Design Tokens ───────────────────────────────────── */
:root {
  --bg:            #0b1120;
  --bg-surface:    #111827;
  --bg-card:       #1a2332;
  --bg-elevated:   #243044;
  --border:        rgba(148,163,184,.12);
  --border-light:  rgba(148,163,184,.20);
  --text:          #f1f5f9;
  --text-muted:    #94a3b8;
  --text-dim:      #64748b;
  --primary:       #6366f1;
  --primary-hover: #818cf8;
  --primary-glow:  rgba(99,102,241,.18);
  --success:       #22c55e;
  --warning:       #f59e0b;
  --danger:        #ef4444;
  --radius-sm:     8px;
  --radius:        12px;
  --radius-lg:     16px;
  --radius-xl:     20px;
  --shadow:        0 8px 32px rgba(0,0,0,.35);
  --tr:            .2s ease;
}

/* ── Reset ───────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
body { overflow: hidden; }
#app { height: 100%; }
button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148,163,184,.18); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148,163,184,.32); }

/* ══════════════════════════════════════════════════════
   AUTH PAGE
   ══════════════════════════════════════════════════════ */
.auth-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background:
    radial-gradient(ellipse at 25% 0%, rgba(99,102,241,.18), transparent 55%),
    radial-gradient(ellipse at 75% 100%, rgba(56,189,248,.10), transparent 50%),
    var(--bg);
}
.auth-container { width: 100%; max-width: 420px; padding: 32px 20px; }
.auth-brand { text-align: center; margin-bottom: 36px; }
.auth-logo {
  width: 56px; height: 56px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 16px; color: #fff;
}
.auth-logo svg { width: 28px; height: 28px; }
.auth-brand h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.auth-sub { color: var(--text-muted); font-size: .9rem; margin-top: 8px; }

.auth-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); padding: 28px; box-shadow: var(--shadow);
}
.auth-tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--bg); border-radius: var(--radius); margin-bottom: 24px;
}
.auth-tab {
  flex: 1; padding: 10px; border: none; background: transparent;
  border-radius: var(--radius-sm); font-weight: 600; font-size: .9rem;
  cursor: pointer; color: var(--text-muted); transition: var(--tr);
}
.auth-tab.is-active { background: var(--primary); color: #fff; }
.auth-form { display: grid; gap: 18px; }
.field { display: grid; gap: 6px; }
.field span { font-size: .84rem; color: var(--text-muted); font-weight: 500; }
.field input {
  padding: 11px 14px; border: 1px solid var(--border-light);
  border-radius: var(--radius); background: var(--bg); transition: border var(--tr);
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.auth-footer { text-align: center; color: var(--text-dim); font-size: .78rem; margin-top: 24px; }
.form-error { background: rgba(239,68,68,.12); color: var(--danger); border: 1px solid rgba(239,68,68,.25); border-radius: var(--radius); padding: 10px 14px; font-size: .88rem; margin-bottom: 12px; }

/* ══════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 22px; border: none; border-radius: var(--radius);
  font-weight: 600; font-size: .88rem; cursor: pointer; transition: var(--tr);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-full { width: 100%; justify-content: center; padding: 12px; }
.btn-danger-outline { background: transparent; border: 1px solid rgba(239,68,68,.3); color: var(--danger); }
.btn-danger-outline:hover { background: rgba(239,68,68,.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; }

/* ══════════════════════════════════════════════════════
   APP LAYOUT (sidebar + content)
   ══════════════════════════════════════════════════════ */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: 240px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg-surface); border-right: 1px solid var(--border);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 20px 18px; font-weight: 700; font-size: 1.05rem;
}
.brand-logo { display: flex; color: var(--primary); }
.brand-logo svg { width: 24px; height: 24px; }
.sidebar-nav { flex: 1; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: var(--radius); cursor: pointer; color: var(--text-muted);
  transition: var(--tr); border: none; background: none; font-size: .88rem; text-align: left; width: 100%;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,.05); }
.nav-item.is-active { color: var(--primary-hover); background: var(--primary-glow); font-weight: 600; }
.nav-icon { display: flex; flex-shrink: 0; }
.nav-icon svg { width: 18px; height: 18px; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px; margin-bottom: 4px; }
.avatar {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .82rem; flex-shrink: 0; color: #fff;
}
.user-meta { overflow: hidden; }
.uname { display: block; font-size: .84rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uemail { display: block; font-size: .73rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-logout { color: var(--text-dim); }
.nav-logout:hover { color: var(--danger); background: rgba(239,68,68,.08); }

/* ── Main Content Area ───────────────────────────────── */
.main-area { flex: 1; overflow-y: auto; padding: 32px 40px; }

/* ══════════════════════════════════════════════════════
   PAGE HEADER
   ══════════════════════════════════════════════════════ */
.page-head { margin-bottom: 28px; }
.page-head h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.page-sub { color: var(--text-muted); font-size: .9rem; margin-top: 4px; }

/* ══════════════════════════════════════════════════════
   DASHBOARD
   ══════════════════════════════════════════════════════ */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  display: flex; align-items: center; gap: 16px; padding: 20px;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  transition: border var(--tr);
}
.stat-card:hover { border-color: rgba(148,163,184,.25); }
.stat-ic {
  width: 46px; height: 46px; display: flex; align-items: center; justify-content: center;
  border-radius: 12px; flex-shrink: 0;
}
.stat-ic svg { width: 22px; height: 22px; }
.stat-ic.c1 { background: rgba(99,102,241,.14); color: var(--primary); }
.stat-ic.c2 { background: rgba(56,189,248,.14); color: #38bdf8; }
.stat-ic.c3 { background: rgba(34,197,94,.14); color: var(--success); }
.stat-val { font-size: 1.3rem; font-weight: 700; }
.stat-lb { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }
.clr-ok { color: var(--success); }
.clr-warn { color: var(--warning); }

.action-row { display: flex; gap: 12px; margin-bottom: 32px; }
.act-card {
  display: flex; align-items: center; gap: 10px; padding: 14px 24px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); cursor: pointer; font-weight: 600;
  font-size: .9rem; color: var(--text); transition: var(--tr);
}
.act-card:hover { border-color: var(--primary); background: var(--primary-glow); }
.act-ic { display: flex; color: var(--primary); }
.act-ic svg { width: 18px; height: 18px; }

.section { margin-top: 8px; }
.sec-title { font-size: 1rem; font-weight: 600; margin-bottom: 14px; }
.recent-list { display: grid; gap: 6px; }
.recent-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: var(--tr);
}
.recent-row:hover { border-color: var(--primary); background: rgba(99,102,241,.06); }
.recent-title { font-weight: 500; font-size: .9rem; }
.recent-meta { font-size: .78rem; color: var(--text-dim); }

/* ══════════════════════════════════════════════════════
   CHAT PAGE
   ══════════════════════════════════════════════════════ */
.chat-page { display: flex; height: calc(100vh - 64px); margin: -32px -40px; }

/* ── Sessions sidebar ────────────────────────────────── */
.chat-side {
  width: 280px; flex-shrink: 0; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--bg-surface);
}
.chat-side-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px 14px;
}
.chat-side-title { font-weight: 600; font-size: .95rem; }
.btn-ic {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: transparent;
  cursor: pointer; color: var(--text-muted); transition: var(--tr);
}
.btn-ic:hover { color: var(--primary); border-color: var(--primary); }
.btn-ic svg { width: 16px; height: 16px; }

.sess-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; display: flex; flex-direction: column; gap: 3px; }
.sess-item {
  display: flex; flex-direction: column; gap: 4px; padding: 12px;
  border: none; border-radius: var(--radius); background: transparent;
  text-align: left; cursor: pointer; transition: var(--tr); color: var(--text); width: 100%;
}
.sess-item:hover { background: rgba(255,255,255,.04); }
.sess-item.is-active { background: var(--primary-glow); }
.sess-t { font-size: .87rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-m { font-size: .73rem; color: var(--text-dim); }
.empty-hint { padding: 24px; text-align: center; color: var(--text-dim); font-size: .84rem; }

/* ── Chat body ───────────────────────────────────────── */
.chat-body { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-hd { padding: 16px 28px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-hd h2 { font-size: 1rem; font-weight: 600; }

.chat-msgs {
  flex: 1; overflow-y: auto; padding: 28px;
  display: flex; flex-direction: column; gap: 24px;
}
.empty-chat {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; color: var(--text-dim); text-align: center; gap: 10px;
}
.empty-ic { color: var(--primary); margin-bottom: 4px; }
.empty-ic svg { width: 44px; height: 44px; }
.empty-chat h3 { font-size: 1.15rem; color: var(--text); font-weight: 600; }
.empty-chat p { font-size: .9rem; }

/* ── Messages ────────────────────────────────────────── */
.msg { display: flex; gap: 12px; max-width: 80%; animation: msgIn .3s ease; }
.msg--user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700; flex-shrink: 0; letter-spacing: .03em;
}
.msg--assistant .msg-avatar { background: linear-gradient(135deg, var(--primary), #8b5cf6); color: #fff; }
.msg--user .msg-avatar { background: rgba(255,255,255,.08); color: var(--text-muted); }
.msg-wrap { min-width: 0; }
.msg-name { font-size: .73rem; color: var(--text-dim); margin-bottom: 5px; }
.msg--user .msg-name { text-align: right; }
.msg-body {
  padding: 14px 18px; border-radius: var(--radius-lg);
  line-height: 1.7; white-space: pre-wrap; word-break: break-word; font-size: .9rem;
}
.msg--assistant .msg-body { background: var(--bg-surface); border: 1px solid var(--border); }
.msg--user .msg-body { background: var(--primary); color: #fff; }

@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Chat input bar ──────────────────────────────────── */
.chat-bar {
  padding: 16px 28px; border-top: 1px solid var(--border);
  flex-shrink: 0; display: flex; gap: 10px; align-items: flex-end;
}
.chat-bar textarea {
  flex: 1; padding: 11px 16px; border: 1px solid var(--border-light);
  border-radius: var(--radius); background: var(--bg-surface);
  resize: none; min-height: 44px; max-height: 200px; line-height: 1.5; transition: border var(--tr);
}
.chat-bar textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.btn-send {
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius); background: var(--primary);
  color: #fff; cursor: pointer; flex-shrink: 0; transition: var(--tr);
}
.btn-send:hover { background: var(--primary-hover); }
.btn-send:disabled { opacity: .35; cursor: not-allowed; }
.btn-send svg { width: 18px; height: 18px; }

/* ══════════════════════════════════════════════════════
   SETTINGS
   ══════════════════════════════════════════════════════ */
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 20px; }
.set-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px;
}
.set-card h3 { display: flex; align-items: center; gap: 8px; font-size: 1rem; margin-bottom: 20px; }
.set-card h3 svg { width: 18px; height: 18px; color: var(--primary); }
.card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.card-top h3 { margin-bottom: 0; }
.info-grid { display: grid; gap: 10px; margin-bottom: 20px; }
.info-r {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--bg); border-radius: var(--radius-sm);
}
.info-r label { font-size: .84rem; color: var(--text-muted); }
.info-r span { font-size: .84rem; font-weight: 500; }
.mono { font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace; font-size: .78rem; }
.muted { color: var(--text-muted); font-size: .9rem; margin-bottom: 16px; line-height: 1.6; }
.st-badge { font-size: .76rem; font-weight: 600; padding: 4px 12px; border-radius: 999px; }
.st-ok { background: rgba(34,197,94,.14); color: var(--success); }
.st-warn { background: rgba(245,158,11,.14); color: var(--warning); }

/* ══════════════════════════════════════════════════════
   QR MODAL
   ══════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 8000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6); backdrop-filter: blur(6px);
  animation: fadeIn .2s ease;
}
.modal-card {
  width: 400px; max-width: 92vw;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: 0 24px 64px rgba(0,0,0,.5);
  animation: modalIn .25s ease;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { display: flex; align-items: center; gap: 8px; font-size: 1rem; }
.modal-head h3 svg { width: 18px; height: 18px; color: var(--primary); }
.modal-body { padding: 24px; text-align: center; }
.modal-desc { color: var(--text-muted); font-size: .9rem; margin-bottom: 20px; }
.qr-box {
  width: 280px; height: 280px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  background: #fff; border-radius: var(--radius-lg); overflow: hidden;
}
.qr-box iframe { border: none; }
.qr-loading { color: var(--text-dim); font-size: .88rem; }
.modal-hint { color: var(--text-dim); font-size: .82rem; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: scale(.95) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* ══════════════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════════════ */
#toast-root {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  padding: 12px 20px; border-radius: var(--radius); font-size: .88rem; font-weight: 500;
  backdrop-filter: blur(16px); border: 1px solid var(--border);
  box-shadow: var(--shadow); pointer-events: auto; animation: toastIn .3s ease;
}
.toast--info    { background: rgba(17,24,39,.92); }
.toast--success { background: rgba(17,24,39,.92); border-color: rgba(34,197,94,.3); color: var(--success); }
.toast--error   { background: rgba(17,24,39,.92); border-color: rgba(239,68,68,.3); color: var(--danger); }
.toast--out     { animation: toastOut .3s ease forwards; }

@keyframes toastIn  { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-12px); } }

/* ══════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .stat-row { grid-template-columns: 1fr 1fr; }
  .set-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { width: 64px; }
  .brand-text, .nav-label, .user-meta { display: none; }
  .sidebar-brand { justify-content: center; padding: 18px 8px; }
  .sidebar-nav { padding: 8px 6px; }
  .nav-item { justify-content: center; padding: 10px; }
  .sidebar-user { justify-content: center; }
  .main-area { padding: 24px 20px; }
  .chat-page { margin: -24px -20px; height: calc(100vh - 48px); }
  .chat-side { width: 200px; }
  .stat-row { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .chat-page { flex-direction: column; }
  .chat-side { width: 100%; height: 160px; flex-shrink: 0; border-right: none; border-bottom: 1px solid var(--border); }
  .sess-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .sess-item { min-width: 180px; }
  .chat-bar { padding: 12px; }
  .chat-msgs { padding: 16px; }
  .msg { max-width: 95%; }
}
