:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #4f46e5;
  --brand-2: #0ea5a4;
  --brand-soft: #eef2ff;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
  --sidebar: #111827;
  --sidebar-2: #1f2937;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.6;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 14px; background: var(--surface); color: var(--ink-2);
  font-weight: 600; font-size: 14px; line-height: 1.2; transition: .16s ease;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(135deg, var(--brand), #6d5dfc); color: #fff; box-shadow: 0 8px 20px rgba(79, 70, 229, .25); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: transparent; }
.btn.ghost:hover { background: rgba(15, 23, 42, .06); }
.btn.ghost.danger { color: var(--danger); }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn.tiny { padding: 4px 8px; font-size: 12px; }
.btn.icon { padding: 8px; width: 38px; height: 38px; }
.btn.block { width: 100%; }

input, textarea, select {
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  padding: 10px 12px; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
label > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }

/* ---------- 登录 ---------- */
.auth-view {
  min-height: 100%;
  display: grid; grid-template-columns: 1.15fr .85fr;
  background:
    radial-gradient(1000px 600px at -10% -20%, rgba(79, 70, 229, .28), transparent 60%),
    radial-gradient(800px 600px at 110% 110%, rgba(14, 165, 164, .22), transparent 55%),
    #0b1020;
}
.auth-visual {
  color: #e2e8f0; padding: 8vh 7vw; display: flex; flex-direction: column; justify-content: center;
}
.auth-visual h1 { font-size: clamp(28px, 3.2vw, 46px); line-height: 1.25; margin: 28px 0 34px; max-width: 15ch; letter-spacing: -.02em; }
.brand-mark {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #14b8a6); color: #fff; font-weight: 800;
  letter-spacing: .04em; box-shadow: 0 18px 40px rgba(20, 184, 166, .25);
}
.brand-mark.small { width: 42px; height: 42px; border-radius: 12px; font-size: 13px; }
.brand-mark.tiny { width: 34px; height: 34px; border-radius: 10px; font-size: 11px; }
.feature-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 16px; max-width: 460px; }
.feature-list li { display: flex; gap: 14px; align-items: center; color: #cbd5e1; font-size: 15px; }
.feature-list span {
  flex: 0 0 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: rgba(255,255,255,.07); color: #a5b4fc; font-size: 12px; font-weight: 700;
}
.auth-card {
  background: var(--surface); align-self: center; justify-self: center;
  width: min(92%, 440px); border-radius: 22px; padding: 34px; box-shadow: 0 30px 90px rgba(0,0,0,.35);
}
.auth-card-head { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.auth-card-head h2 { margin: 0; font-size: 19px; }
.auth-card-head p { margin: 2px 0 0; font-size: 13px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 11px; margin-bottom: 20px; }
.tab {
  flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 8px;
  font-weight: 600; color: var(--muted); font-size: 14px;
}
.tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px rgba(15,23,42,.08); }
.stack { display: grid; gap: 16px; }
.form-error { margin: 0; color: var(--danger); font-size: 13px; min-height: 18px; }
.auth-foot { font-size: 12px; margin: 20px 0 0; text-align: center; }
.demo-badge {
  margin-top: 14px; padding: 9px 12px; border-radius: 9px; font-size: 12px; text-align: center;
  color: #92400e; background: #fffbeb; border: 1px solid #fde68a;
}

/* ---------- 主布局 ---------- */
.app { height: 100vh; display: grid; grid-template-columns: 292px minmax(0, 1fr) 330px; overflow: hidden; }
.sidebar {
  background: linear-gradient(180deg, #111827, #0b1220); color: #e5e7eb;
  display: flex; flex-direction: column; padding: 18px 14px; gap: 10px; min-height: 0;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 12px; }
.sidebar-head-actions { display: flex; align-items: center; gap: 2px; }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14px; }
.brand-text span { font-size: 11px; color: #94a3b8; letter-spacing: .06em; }
.sidebar .btn.ghost { color: #cbd5e1; }
.sidebar .btn.ghost:hover { background: rgba(255,255,255,.08); }
.btn.new-chat {
  background: rgba(99, 102, 241, .18); color: #c7d2fe; border: 1px solid rgba(129,140,248,.25);
  justify-content: flex-start; margin-bottom: 10px;
}
.btn.new-chat:hover { background: rgba(99, 102, 241, .28); }
.sidebar-label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: #64748b; padding: 4px 8px; }
.thread-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 3px; min-height: 0; }
.thread-item {
  position: relative; border-radius: 9px; display: flex; align-items: center;
  width: 100%; overflow: hidden;
}
.thread-item:hover { background: rgba(255,255,255,.06); }
.thread-item.active { background: rgba(99,102,241,.2); color: #fff; }
.thread-select {
  border: 0; background: transparent; color: inherit; text-align: left;
  padding: 10px 26px 10px 10px; display: flex; flex-direction: column; gap: 2px;
  width: 100%; min-width: 0; overflow: hidden;
}
.thread-item strong { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-item span { font-size: 11px; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-del {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: #94a3b8; font-size: 18px; line-height: 1;
  width: 24px; height: 24px; border-radius: 6px; opacity: 0; transition: .15s;
}
.thread-item:hover .thread-del { opacity: 1; }
.thread-del:hover { background: rgba(220,38,38,.2); color: #fca5a5; }
.thread-empty { color: #64748b; font-size: 12px; padding: 10px; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.07); padding-top: 12px; display: grid; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 0 4px; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg,#6366f1,#14b8a6); display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; flex: 0 0 auto; }
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.user-meta strong { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta span { font-size: 11px; color: #64748b; }
.foot-actions { display: flex; gap: 6px; }
.foot-actions .btn { flex: 1; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.topbar {
  height: 66px; display: flex; align-items: center; gap: 12px; padding: 0 24px;
  border-bottom: 1px solid var(--line); background: rgba(255,255,255,.85); backdrop-filter: blur(10px);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 16px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-title span { font-size: 12px; }
.topbar-actions { display: flex; gap: 8px; }

.chat-scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; min-height: 0; }
.messages { max-width: 880px; margin: 0 auto; padding: 28px 24px 10px; display: flex; flex-direction: column; gap: 20px; }
.welcome { max-width: 780px; margin: 3vh auto 0; padding: 20px 24px 40px; text-align: center; }
.welcome-mark { width: 54px; height: 54px; border-radius: 16px; margin: 0 auto 16px; display: grid; place-items: center; background: linear-gradient(135deg,var(--brand),var(--brand-2)); color: #fff; font-weight: 800; box-shadow: var(--shadow); }
.welcome h2 { margin: 0 0 8px; font-size: 24px; letter-spacing: -.02em; }
.welcome p { margin: 0 auto; max-width: 520px; font-size: 14px; }
.prompt-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 26px; text-align: left; }
.prompt-card {
  border: 1px solid var(--line); background: var(--surface); border-radius: 13px; padding: 14px;
  display: flex; flex-direction: column; gap: 4px; transition: .16s; box-shadow: 0 2px 8px rgba(15,23,42,.03);
}
.prompt-card:hover { border-color: #c7d2fe; transform: translateY(-2px); box-shadow: 0 10px 24px rgba(79,70,229,.1); }
.prompt-card strong { font-size: 13px; color: var(--ink); }
.prompt-card span { font-size: 12px; color: var(--muted); line-height: 1.45; }

.msg { display: flex; gap: 12px; align-items: flex-start; animation: rise .22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg-user { flex-direction: row-reverse; }
.msg-avatar { width: 32px; height: 32px; border-radius: 10px; flex: 0 0 auto; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.msg-user .msg-avatar { background: #e0e7ff; color: #4338ca; }
.msg-assistant .msg-avatar { background: linear-gradient(135deg,var(--brand),var(--brand-2)); color: #fff; }
.msg-body { max-width: min(76%, 720px); }
.msg-user .msg-body { background: var(--brand); color: #fff; border-radius: 14px 4px 14px 14px; padding: 10px 14px; }
.msg-assistant .msg-body { background: var(--surface); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 12px 16px; box-shadow: 0 2px 8px rgba(15,23,42,.03); }
.msg-text { word-break: break-word; }
.msg-text p { margin: 0 0 10px; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text h1, .msg-text h2, .msg-text h3 { margin: 12px 0 6px; font-size: 16px; }
.msg-text ul { margin: 6px 0; padding-left: 20px; }
.msg-text code { background: rgba(15,23,42,.06); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.msg-text pre { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-size: 13px; }
.msg-text pre code { background: transparent; padding: 0; color: inherit; }
.msg-time { font-size: 11px; color: var(--muted); margin-top: 6px; }
.msg-user .msg-time { color: rgba(255,255,255,.7); text-align: right; }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--brand); }
@keyframes blink { 50% { opacity: 0; } }

.interrupt-card { border: 1px solid #fcd34d; background: #fffbeb; border-radius: 12px; padding: 14px; margin-top: 10px; }
.interrupt-card h4 { margin: 0 0 8px; font-size: 14px; color: #92400e; }
.interrupt-req { background: #fff; border: 1px solid #fde68a; border-radius: 8px; padding: 10px; margin-bottom: 8px; font-size: 13px; }
.interrupt-req code { display: block; margin-top: 6px; white-space: pre-wrap; word-break: break-all; color: #78350f; font-size: 12px; }
.interrupt-actions { display: flex; gap: 8px; margin-top: 8px; }

.composer-wrap { padding: 10px 24px 16px; background: linear-gradient(180deg, rgba(244,246,251,0), var(--bg) 35%); }
.composer {
  max-width: 880px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 8px 8px 8px 16px; display: flex; align-items: flex-end; gap: 8px;
  box-shadow: 0 10px 30px rgba(15,23,42,.07); transition: border .15s;
}
.composer:focus-within { border-color: #a5b4fc; }
.composer textarea { border: 0; box-shadow: none; padding: 8px 0; resize: none; max-height: 180px; flex: 1; background: transparent; font-size: 14.5px; }
.composer textarea:focus { box-shadow: none; }
.btn.send { width: 40px; height: 40px; padding: 0; border-radius: 11px; flex: 0 0 auto; }
.composer-hint { max-width: 880px; margin: 7px auto 0; font-size: 11px; text-align: center; }
.run-status {
  max-width: 880px; margin: 0 auto 8px; display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 10px;
}
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-2); box-shadow: 0 0 0 0 rgba(14,165,164,.5); animation: pulse 1.4s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(14,165,164,0); } 100% { box-shadow: 0 0 0 0 rgba(14,165,164,0); } }

/* ---------- 文件面板 ---------- */
.files-panel {
  background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column;
  min-width: 0; min-height: 0; padding: 18px 16px;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-head p { margin: 2px 0 0; font-size: 12px; }
.panel-tools { display: flex; gap: 6px; margin: 14px 0 8px; }
.upload-btn { position: relative; overflow: hidden; }
.breadcrumb { font-size: 12px; color: var(--muted); padding: 6px 2px 10px; word-break: break-all; border-bottom: 1px solid var(--line); }
.files-list { flex: 1; overflow-y: auto; min-height: 0; padding-top: 6px; }
.file-row { display: flex; align-items: center; gap: 9px; padding: 8px 6px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.file-row:hover { background: var(--surface-2); }
.file-row .file-icon { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; background: var(--brand-soft); color: var(--brand); font-size: 10px; font-weight: 700; flex: 0 0 auto; }
.file-row .file-icon.dir { background: #ecfdf5; color: var(--ok); }
.file-row .file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .file-size { color: var(--muted); font-size: 11px; }
.files-empty { color: var(--muted); font-size: 12px; padding: 18px 6px; text-align: center; }
.storage-bar { border-top: 1px solid var(--line); padding-top: 12px; font-size: 11px; color: var(--muted); }
.storage-track { height: 4px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.storage-fill { height: 100%; background: linear-gradient(90deg,var(--brand),var(--brand-2)); border-radius: 3px; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.55); backdrop-filter: blur(4px); z-index: 50; display: grid; place-items: center; padding: 24px; }
.modal-card { background: var(--surface); border-radius: 18px; width: min(96vw, 620px); max-height: 88vh; overflow: auto; padding: 22px; box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.modal-card.wide { width: min(96vw, 980px); }
.modal-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head p { margin: 2px 0 0; font-size: 12px; word-break: break-all; }
.modal-actions { display: flex; gap: 6px; align-items: center; }
.file-preview { background: #0f172a; color: #e2e8f0; padding: 16px; border-radius: 12px; overflow: auto; max-height: 60vh; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.inline-form input { flex: 1 1 180px; }
.stats-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.stat-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 110px; }
.stat-card strong { display: block; font-size: 18px; }
.stat-card span { font-size: 11px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tr:hover td { background: var(--surface-2); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: var(--surface-2); color: var(--ink-2); }
.pill.admin { background: #eef2ff; color: var(--brand); }
.pill.off { background: #fef2f2; color: var(--danger); }
.pill.on { background: #ecfdf5; color: var(--ok); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 80; box-shadow: var(--shadow); }

.mobile-only { display: none; }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: 270px minmax(0, 1fr); }
  .files-panel { position: fixed; right: 0; top: 0; bottom: 0; width: 340px; z-index: 40; box-shadow: -10px 0 40px rgba(15,23,42,.18); transform: translateX(105%); visibility: hidden; transition: transform .2s ease, visibility .2s; }
  .files-panel.open { transform: translateX(0); visibility: visible; }
  .mobile-only { display: inline-flex; }
  #files-toggle { display: inline-flex; }
}
@media (min-width: 1181px) {
  #files-panel { transform: none !important; }
  #files-close { display: none; }
}
@media (max-width: 860px) {
  .auth-view { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .auth-card { width: min(92%, 440px); }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 292px; z-index: 45; transform: translateX(-105%); visibility: hidden; transition: transform .2s ease, visibility .2s; box-shadow: 20px 0 50px rgba(0,0,0,.3); }
  .sidebar.open { transform: translateX(0); visibility: visible; }
  #files-panel { width: min(90vw, 340px); }
  .prompt-grid { grid-template-columns: 1fr; }
  .msg-body { max-width: 88%; }
  .topbar { padding: 0 14px; }
  .messages { padding: 20px 14px 6px; }
  .composer-wrap { padding: 8px 12px 14px; }
  .modal { padding: 12px; }
}
