:root {
  --bg: #0f1115;
  --panel: #181b22;
  --line: #2a2f3a;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --danger: #e5534b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

header strong { letter-spacing: .5px; }
.head-right { display: flex; align-items: center; gap: 10px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  padding: 20px;
  height: calc(100vh - 57px);
}

.chat {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.me { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.ai { align-self: flex-start; background: #20242e; white-space: normal; }

.answer { white-space: normal; word-break: break-word; }
.answer.streaming { white-space: pre-wrap; }
.answer p { margin: 6px 0; }
.answer h1, .answer h2, .answer h3, .answer h4 {
  margin: 12px 0 6px;
  font-size: 1.05em;
}
.answer ul, .answer ol { margin: 6px 0; padding-left: 22px; }
.answer li { display: list-item; padding: 0; border: 0; }
.answer code {
  background: #11141a;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .9em;
}
.answer pre {
  background: #11141a;
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
}
.answer pre code { background: none; padding: 0; }
.answer blockquote {
  border-left: 3px solid var(--line);
  margin: 8px 0;
  padding-left: 10px;
  color: var(--muted);
}
.answer table { border-collapse: collapse; margin: 8px 0; }
.answer th, .answer td { border: 1px solid var(--line); padding: 6px 8px; }
.answer a { color: var(--accent); }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

.reasoning {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.reasoning summary {
  cursor: pointer;
  user-select: none;
}

.reasoning-text {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 6px 0 0;
  max-height: 240px;
  overflow-y: auto;
  font: inherit;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.status {
  margin: 0;
  padding: 0 14px 10px;
  min-height: 18px;
}

.composer textarea {
  flex: 1;
  resize: none;
  background: #11141a;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

.side { overflow-y: auto; padding-right: 4px; }

h2 { font-size: 13px; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
section { margin-bottom: 26px; }

.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.card h2 { margin-bottom: 2px; }
.card p { margin: 2px 0 0; font-size: 17px; font-variant-numeric: tabular-nums; }
.card .sub { font-size: 11px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
th { font-weight: 500; color: var(--muted); font-size: 11px; }

select, input[type="file"] {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

input:not([type]), input[type="text"] {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  min-width: 0;
}

button {
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  color: #fff;
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }

form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

progress { width: 100%; height: 8px; margin: 8px 0; }

ul { list-style: none; padding: 0; margin: 8px 0 0; }
li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }

.login { min-height: 100vh; display: grid; place-items: center; }

.login form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
}

.login h1 { margin: 0; font-size: 20px; }
.error { color: var(--danger); font-size: 13px; margin: 0; }
.sub { color: var(--muted); font-size: 12px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .chat { height: 70vh; }
  .side { overflow: visible; }
}
