:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  background: #eef3f7;
  color: #172033;
  --ink: #172033;
  --muted: #667085;
  --line: #d8e1e8;
  --panel: rgba(255, 255, 255, 0.9);
  --brand: #1f6f78;
  --brand-dark: #102a43;
  --accent: #e36a4a;
  --green: #2f9e73;
  --soft: #f7fafc;
  --shadow: 0 24px 70px rgba(16, 42, 67, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(140deg, rgba(31, 111, 120, 0.16), transparent 34%),
    linear-gradient(25deg, rgba(227, 106, 74, 0.16), transparent 30%),
    #eef3f7;
}

body.is-authenticated .login-view {
  display: none;
}

body:not(.is-authenticated) .shell {
  display: none;
}

button,
textarea,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.shell {
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
}

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

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  padding: 28px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-brand {
  margin-bottom: 4px;
  color: var(--ink);
}

.login-brand p {
  color: var(--muted);
}

.login-panel label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

.login-panel input {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  outline: none;
  color: var(--ink);
  background: #ffffff;
}

.login-panel input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 111, 120, 0.16);
}

.login-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--brand);
  cursor: pointer;
  font-weight: 800;
}

.login-button:hover {
  background: #175c64;
}

.login-button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: #b42318;
  font-size: 14px;
}

.login-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.login-links {
  display: flex;
  justify-content: center;
}

.login-link {
  color: var(--brand);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.login-link:hover {
  text-decoration: underline;
}

.workspace {
  width: min(1180px, 100%);
  height: calc(100vh - 48px);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.side-panel {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 22px;
  min-height: 0;
  background: #102a43;
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f0c35b;
  color: #102a43;
  font-weight: 800;
  font-size: 22px;
}

.brand h1,
.brand p,
.topbar h2,
.study-card p {
  margin: 0;
}

.brand h1 {
  font-size: 24px;
}

.brand p {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 14px;
}

.user-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.user-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.user-head .eyebrow {
  margin: 0;
}

.user-head strong {
  overflow: hidden;
  color: #ffffff;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 7px 10px;
  color: rgba(255, 255, 255, 0.78);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.logout-button:hover {
  background: rgba(255, 255, 255, 0.14);
}

.study-card {
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
}

.eyebrow,
.section-label {
  display: block;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.study-card strong {
  display: block;
  font-size: 20px;
}

.study-card p {
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  word-break: break-word;
}

.quick-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: end;
}

.quick-list button,
.new-chat-button,
.history-head button,
.history-item {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 10px 12px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
  text-align: left;
  cursor: pointer;
}

.quick-list button:hover,
.new-chat-button:hover,
.history-head button:hover,
.history-item:hover {
  background: rgba(255, 255, 255, 0.14);
}

.new-chat-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #f0c35b;
  color: #102a43;
  font-weight: 800;
  text-align: center;
}

.new-chat-button:hover {
  background: #ffd36b;
}

.history-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-head .eyebrow {
  margin: 0;
}

.history-head button {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.conversation-list {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(240, 195, 91, 0.8) rgba(255, 255, 255, 0.12);
}

.conversation-list::-webkit-scrollbar {
  width: 8px;
}

.conversation-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}

.conversation-list::-webkit-scrollbar-thumb {
  background: rgba(240, 195, 91, 0.8);
  border-radius: 999px;
}

.history-item {
  min-height: 0;
  display: grid;
  gap: 5px;
  width: 100%;
  text-align: left;
}

.history-item.is-active {
  border-color: rgba(240, 195, 91, 0.7);
  background: rgba(240, 195, 91, 0.16);
}

.history-title {
  overflow: hidden;
  color: #ffffff;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta,
.history-empty {
  color: rgba(255, 255, 255, 0.64);
  font-size: 12px;
}

.history-empty {
  padding: 10px 2px;
}

.chat-panel {
  position: relative;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: rgba(247, 250, 252, 0.92);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
}

.topbar h2 {
  color: var(--ink);
  font-size: 22px;
}

.section-label {
  margin-bottom: 4px;
  color: var(--green);
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--brand-dark);
  background: #ffffff;
  cursor: pointer;
}

.icon-button svg,
.send-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  padding: 22px;
  padding-right: 28px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: auto;
  scrollbar-color: rgba(31, 111, 120, 0.62) rgba(216, 225, 232, 0.65);
}

.messages::-webkit-scrollbar {
  width: 20px;
}

.messages::-webkit-scrollbar-track {
  background: rgba(216, 225, 232, 0.65);
  border-radius: 999px;
}

.messages::-webkit-scrollbar-thumb {
  border: 4px solid rgba(247, 250, 252, 0.92);
  border-radius: 999px;
  background: rgba(31, 111, 120, 0.72);
}

.messages::-webkit-scrollbar-thumb:hover {
  background: rgba(31, 111, 120, 0.92);
}

.jump-bottom {
  position: absolute;
  right: 32px;
  bottom: 92px;
  z-index: 2;
  border: 1px solid rgba(31, 111, 120, 0.22);
  border-radius: 999px;
  padding: 8px 14px;
  color: #ffffff;
  background: var(--brand);
  box-shadow: 0 12px 26px rgba(16, 42, 67, 0.18);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.jump-bottom.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.message {
  max-width: 88%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.system {
  align-self: center;
  max-width: 92%;
}

.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  flex: 0 0 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #ffffff;
  font-weight: 700;
}

.message.user .avatar {
  background: var(--accent);
}

.message.system .avatar {
  background: #f0c35b;
  color: var(--brand-dark);
}

.bubble {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 15px;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(16, 42, 67, 0.06);
}

.message.user .bubble {
  border-color: rgba(31, 111, 120, 0.1);
  background: #dff4ef;
}

.message.system .bubble {
  border-color: rgba(227, 106, 74, 0.22);
  background: #fff5ef;
}

.content {
  line-height: 1.72;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.content > :first-child {
  margin-top: 0;
}

.content > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 14px 0 8px;
  line-height: 1.35;
}

.markdown-body h1 {
  font-size: 22px;
}

.markdown-body h2 {
  font-size: 19px;
}

.markdown-body h3 {
  font-size: 17px;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body table,
.markdown-body pre {
  margin: 10px 0;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 22px;
}

.markdown-body code {
  border-radius: 5px;
  padding: 2px 5px;
  background: #edf2f7;
  color: #9a3412;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.92em;
}

.markdown-body pre {
  overflow: auto;
  border-radius: 8px;
  padding: 12px;
  background: #102a43;
  color: #f8fafc;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 8px;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
}

.markdown-body th {
  background: #e8f3f1;
}

.markdown-body blockquote {
  border-left: 4px solid var(--green);
  padding-left: 12px;
  color: var(--muted);
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
  max-width: 100%;
}

.katex {
  white-space: normal;
}

.katex-display > .katex {
  white-space: nowrap;
}

.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 12px;
  padding: 16px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
}

.composer textarea {
  width: 100%;
  min-height: 48px;
  max-height: 160px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  outline: none;
  color: var(--ink);
  background: #ffffff;
}

.composer textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 111, 120, 0.16);
}

.send-button {
  min-width: 92px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--brand);
  cursor: pointer;
}

.send-button:hover {
  background: #175c64;
}

.send-button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

@media (max-width: 860px) {
  .shell {
    padding: 0;
  }

  .workspace {
    height: 100vh;
    grid-template-columns: 1fr;
    border-radius: 0;
  }

  .side-panel {
    grid-template-rows: auto;
    gap: 12px;
    padding: 16px;
  }

  .study-card,
  .quick-list,
  .history-panel,
  .new-chat-button {
    display: none;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .brand h1 {
    font-size: 21px;
  }

  .message {
    max-width: 96%;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 14px 16px;
  }

  .messages {
    padding: 16px;
    padding-right: 24px;
  }

  .composer {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .send-button {
    width: 100%;
  }
}
