:root {
  color-scheme: dark;
  --bg: #080b14;
  --panel: rgba(20, 26, 43, .86);
  --line: rgba(148, 163, 184, .18);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #7c3aed;
  --accent-strong: #8b5cf6;
  --danger: #fda4af;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background:
    radial-gradient(circle at 18% 0%, rgba(124, 58, 237, .3), transparent 30rem),
    radial-gradient(circle at 100% 100%, rgba(14, 116, 144, .22), transparent 32rem),
    var(--bg);
}

button, input { font: inherit; }
button, input { border-radius: 12px; }
button:focus-visible, input:focus-visible {
  outline: 3px solid rgba(167, 139, 250, .65);
  outline-offset: 2px;
}

.auth-page { display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(100%, 420px);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0, 0, 0, .45);
  backdrop-filter: blur(18px);
}
.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  margin-bottom: 24px;
  border-radius: 15px;
  color: white;
  font-size: 22px;
  font-weight: 800;
  background: linear-gradient(145deg, var(--accent-strong), #2563eb);
  box-shadow: 0 12px 30px rgba(124, 58, 237, .35);
}
.eyebrow {
  margin: 0 0 8px;
  color: #a78bfa;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
}
h1 { margin: 0; letter-spacing: -.035em; }
.auth-card h1 { font-size: 32px; }
.intro, .privacy-note, .welcome-panel p { color: var(--muted); line-height: 1.7; }
.intro { margin: 12px 0 25px; }
.privacy-note { margin: 20px 0 0; font-size: 12px; text-align: center; }
.alert {
  padding: 12px 14px;
  border: 1px solid rgba(251, 113, 133, .3);
  border-radius: 12px;
  color: var(--danger);
  background: rgba(159, 18, 57, .18);
}
.login-form { display: grid; gap: 17px; }
.login-form label { display: grid; gap: 8px; }
.login-form label span { color: #cbd5e1; font-size: 13px; }
.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  padding: 13px 14px;
  color: var(--text);
  background: rgba(2, 6, 23, .65);
}
.login-form button, .secondary-button {
  border: 0;
  padding: 13px 16px;
  color: white;
  font-weight: 700;
  cursor: pointer;
}
.login-form button {
  margin-top: 4px;
  background: linear-gradient(135deg, var(--accent), #2563eb);
}
.login-form button:hover { filter: brightness(1.1); }
.workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0;
}
.workspace-header strong { font-size: 18px; }
.secondary-button {
  border: 1px solid var(--line);
  padding: 9px 13px;
  color: #dbeafe;
  background: rgba(30, 41, 59, .7);
}
.workspace-shell {
  display: grid;
  width: min(1080px, calc(100% - 32px));
  min-height: calc(100vh - 100px);
  margin: 0 auto;
  place-items: center;
  padding-bottom: 80px;
}
.welcome-panel {
  width: min(100%, 650px);
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 24px;
  text-align: center;
  background: var(--panel);
  box-shadow: 0 25px 70px rgba(0, 0, 0, .35);
}
.welcome-panel h1 { margin-top: 16px; font-size: clamp(30px, 5vw, 48px); }
.status-pill {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  color: #a7f3d0;
  font-size: 12px;
  background: rgba(5, 150, 105, .18);
}

@media (max-width: 520px) {
  .auth-page { padding: 14px; }
  .auth-card { padding: 25px 20px; border-radius: 20px; }
  .welcome-panel { padding: 30px 20px; }
}
/* Chat workspace */
.workspace-page { overflow: hidden; }
.app-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: rgba(7, 10, 20, .82);
  backdrop-filter: blur(18px);
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 4px; }
.sidebar-brand .eyebrow { margin-bottom: 3px; }
.brand-mark.compact { width: 38px; height: 38px; margin: 0; border-radius: 12px; font-size: 17px; }
.brand-mark.large { width: 58px; height: 58px; margin: 0 auto 22px; }
.new-chat-button {
  width: 100%;
  margin-top: 24px;
  border: 1px solid rgba(139, 92, 246, .32);
  padding: 11px 14px;
  color: #ede9fe;
  text-align: left;
  cursor: pointer;
  background: rgba(124, 58, 237, .12);
}
.new-chat-button:hover { background: rgba(124, 58, 237, .22); }
.sidebar-bottom { display: grid; gap: 14px; }
.privacy-card { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(15, 23, 42, .5); }
.privacy-card strong { font-size: 13px; }
.privacy-card p { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.full-width { width: 100%; }
.chat-shell { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; height: 100vh; }
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 11, 20, .74);
  backdrop-filter: blur(16px);
}
.chat-header > div { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-header strong { white-space: nowrap; }
.model-status, .private-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 11px;
  white-space: nowrap;
}
.model-status { padding: 5px 9px; color: #a7f3d0; background: rgba(5, 150, 105, .14); }
.model-status::before { width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: #34d399; content: ""; }
.model-status.missing { color: #fde68a; background: rgba(217, 119, 6, .15); }
.model-status.missing::before { background: #fbbf24; }
.private-badge { padding: 6px 10px; color: #c4b5fd; border: 1px solid rgba(139, 92, 246, .25); }
.message-list { overflow-y: auto; padding: 40px max(24px, calc((100% - 820px) / 2)); scroll-behavior: smooth; }
.empty-state { max-width: 720px; margin: 9vh auto 0; text-align: center; }
.empty-state h1 { font-size: clamp(32px, 5vw, 48px); }
.empty-state > p { margin: 14px 0 28px; color: var(--muted); }
.prompt-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.prompt-grid button {
  border: 1px solid var(--line);
  padding: 14px;
  color: #cbd5e1;
  cursor: pointer;
  background: rgba(15, 23, 42, .58);
}
.prompt-grid button:hover { border-color: rgba(139, 92, 246, .45); color: white; }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 13px; max-width: 820px; margin: 0 auto 22px; }
.message-label {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 10px;
  color: white;
  font-size: 11px;
  font-weight: 800;
  background: #334155;
}
.message.assistant .message-label { background: linear-gradient(145deg, var(--accent), #2563eb); }
.message-content {
  min-width: 0;
  padding: 5px 0;
  color: #e2e8f0;
  line-height: 1.75;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.message.user .message-content { color: white; }
.message.pending .message-content { color: var(--muted); }
.composer-area { padding: 14px max(24px, calc((100% - 820px) / 2)) 18px; background: linear-gradient(transparent, var(--bg) 24%); }
.chat-error { max-width: 820px; margin: 0 auto 10px; padding: 10px 13px; border: 1px solid rgba(251, 113, 133, .3); border-radius: 11px; color: var(--danger); background: rgba(159, 18, 57, .18); }
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 820px;
  margin: 0 auto;
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, .24);
  border-radius: 18px;
  background: rgba(20, 26, 43, .94);
  box-shadow: 0 18px 45px rgba(0, 0, 0, .3);
}
.composer:focus-within { border-color: rgba(139, 92, 246, .55); }
.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 180px;
  resize: none;
  border: 0;
  padding: 9px 10px;
  color: var(--text);
  line-height: 1.5;
  outline: 0;
  background: transparent;
}
.composer button {
  flex: 0 0 auto;
  border: 0;
  padding: 10px 15px;
  color: white;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #2563eb);
}
button:disabled { cursor: not-allowed; opacity: .48; }
.composer-note { margin: 8px auto 0; color: #64748b; font-size: 11px; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .chat-header { padding: 12px 16px; }
  .message-list { padding: 28px 16px; }
  .composer-area { padding: 12px 12px 14px; }
  .prompt-grid { grid-template-columns: 1fr; }
  .empty-state { margin-top: 5vh; }
  .private-badge { display: none; }
}
/* Persistent conversation navigation */
.sidebar { min-height: 0; }
.sidebar-main {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}
.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 7px 9px;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
}
.history-heading small { color: #64748b; font-size: 10px; font-weight: 600; }
.conversation-list {
  display: grid;
  min-height: 0;
  gap: 5px;
  overflow-y: auto;
  padding: 2px 2px 16px;
}
.conversation-item {
  display: grid;
  width: 100%;
  gap: 4px;
  border: 1px solid transparent;
  padding: 10px 11px;
  color: #cbd5e1;
  text-align: left;
  cursor: pointer;
  background: transparent;
}
.conversation-item:hover { background: rgba(148, 163, 184, .08); }
.conversation-item.active {
  border-color: rgba(139, 92, 246, .28);
  color: white;
  background: rgba(124, 58, 237, .16);
}
.conversation-item-title {
  overflow: hidden;
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-item small { color: #64748b; font-size: 10px; }
.history-empty { margin: 10px 7px; color: #64748b; font-size: 12px; }
.chat-heading { overflow: hidden; }
.chat-heading strong { overflow: hidden; text-overflow: ellipsis; }
.header-actions { justify-content: flex-end; }
.header-actions form { margin: 0; }
.header-button {
  border: 1px solid var(--line);
  padding: 8px 11px;
  color: #dbeafe;
  font-size: 12px;
  cursor: pointer;
  background: rgba(30, 41, 59, .62);
}
.header-button:hover:not(:disabled) { border-color: rgba(139, 92, 246, .42); color: white; }
.danger-button { color: #fecdd3; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  .mobile-only { display: inline-flex; }
  .chat-header { gap: 10px; }
  .chat-heading { display: grid !important; gap: 4px !important; }
  .header-actions { gap: 6px !important; }
  .header-button { padding: 7px 9px; }
}

@media (max-width: 480px) {
  .chat-header { align-items: flex-start; }
  .chat-header strong { max-width: 36vw; }
  .header-button { font-size: 11px; }
}