:root {
  color-scheme: light;
  --ink: #151821;
  --ink-2: #252b36;
  --paper: #fbfaf6;
  --surface: #ffffff;
  --surface-soft: #f3f0e8;
  --line: #ded9cd;
  --line-strong: #c9c0ae;
  --text: #1b1d22;
  --muted: #6f6a5f;
  --accent: #b35a2a;
  --accent-strong: #8f3f1d;
  --blue: #2f5f8f;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(27, 29, 34, 0.12);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--paper);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    linear-gradient(90deg, rgba(21, 24, 33, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(21, 24, 33, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(179, 90, 42, 0.38);
  outline-offset: 2px;
}

h1,
h2,
p {
  margin: 0;
}

.hidden {
  display: none !important;
}

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

.loginCard {
  width: min(440px, 100%);
  display: grid;
  gap: 18px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.loginCard h1 {
  font-size: 28px;
  line-height: 1.15;
  font-weight: 700;
}

.loginCard p,
.brandRow p,
.chatHeader p,
.sessionItem span {
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 12px 13px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 44px;
  max-height: 180px;
  resize: none;
}

.loginCard button,
#sendButton,
.iconButton {
  border: 0;
  border-radius: 6px;
  color: #fffaf4;
  background: var(--ink);
}

.loginCard button,
#sendButton {
  padding: 12px 16px;
  font-weight: 700;
}

.loginCard button:hover,
#sendButton:hover,
.iconButton:hover {
  background: #0d1017;
}

.error {
  min-height: 20px;
  color: var(--danger);
}

.appShell {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 308px minmax(0, 1fr);
}

.sidebar {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-right: 1px solid rgba(255, 250, 244, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 250, 244, 0.07), transparent 170px),
    var(--ink);
  color: #fffaf4;
}

.brandRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255, 250, 244, 0.12);
}

.brandRow h1 {
  font-size: 20px;
  line-height: 1.18;
  font-weight: 800;
}

.brandRow p {
  margin-top: 4px;
  color: rgba(255, 250, 244, 0.6);
  font-size: 12px;
}

.iconButton {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-size: 24px;
  line-height: 1;
  background: var(--accent);
}

.sessionList {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px;
}

.sessionItem {
  width: 100%;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0;
  background: transparent;
  color: #fffaf4;
}

.sessionItem + .sessionItem {
  margin-top: 4px;
}

.sessionItem:hover,
.sessionItem.active {
  background: rgba(255, 250, 244, 0.08);
  border-color: rgba(255, 250, 244, 0.18);
}

.sessionItem.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.sessionMain {
  min-width: 0;
  display: grid;
  gap: 6px;
  text-align: left;
  border: 0;
  padding: 12px 4px 12px 13px;
  background: transparent;
  color: inherit;
}

.sessionItem strong {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sessionItem span {
  color: rgba(255, 250, 244, 0.56);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sessionMenuShell {
  position: relative;
  align-self: stretch;
  display: grid;
  place-items: start center;
  padding: 8px 8px 0 0;
}

.sessionMenuButton {
  width: 30px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 250, 244, 0.74);
  font-weight: 800;
  line-height: 1;
}

.sessionMenuButton:hover {
  background: rgba(255, 250, 244, 0.12);
  color: #fffaf4;
}

.sessionMenu {
  position: absolute;
  z-index: 20;
  top: 38px;
  right: 6px;
  width: 112px;
  display: none;
  padding: 6px;
  border: 1px solid rgba(255, 250, 244, 0.18);
  border-radius: 8px;
  background: #242934;
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.28);
}

.sessionMenu.open {
  display: grid;
  gap: 4px;
}

.sessionMenu button {
  border: 0;
  border-radius: 6px;
  padding: 8px 9px;
  background: transparent;
  color: rgba(255, 250, 244, 0.88);
  text-align: left;
}

.sessionMenu button:hover {
  background: rgba(255, 250, 244, 0.1);
}

.sidebarFooter {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(255, 250, 244, 0.12);
}

.secondaryButton {
  border: 1px solid rgba(255, 250, 244, 0.18);
  border-radius: 6px;
  padding: 9px 10px;
  background: rgba(255, 250, 244, 0.06);
  color: rgba(255, 250, 244, 0.84);
}

.secondaryButton:hover {
  background: rgba(255, 250, 244, 0.12);
}

.dangerText {
  color: #ffb4a9;
}

.chatShell {
  min-width: 0;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chatHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 246, 0.96);
  backdrop-filter: blur(10px);
}

.chatHeader h2 {
  max-width: min(760px, 64vw);
  font-size: 20px;
  line-height: 1.25;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chatHeader p {
  max-width: min(760px, 64vw);
  margin-top: 5px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.statusBadge {
  flex: 0 0 auto;
  min-width: 92px;
  text-align: center;
  border: 1px solid rgba(179, 90, 42, 0.22);
  border-radius: 999px;
  padding: 7px 12px;
  background: #fff4ea;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
}

.messageList {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 30px clamp(18px, 6vw, 76px);
  scroll-behavior: smooth;
}

.emptyState {
  width: min(560px, 100%);
  margin: 80px auto 0;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 22px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  text-align: center;
}

.message {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

.message.user {
  justify-content: end;
}

.message.user .bubble {
  border-color: rgba(47, 95, 143, 0.18);
  background: #eef6ff;
}

.bubble {
  width: fit-content;
  max-width: min(780px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 22px rgba(27, 29, 34, 0.06);
  line-height: 1.68;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.markdownBody {
  white-space: normal;
}

.markdownBody p,
.markdownBody ul,
.markdownBody h3 {
  margin: 0;
}

.markdownBody p + p,
.markdownBody ul + p,
.markdownBody p + ul,
.markdownBody h3 + p {
  margin-top: 12px;
}

.markdownBody h3 {
  font-size: 16px;
  line-height: 1.45;
}

.markdownBody ul {
  padding-left: 1.2em;
}

.markdownBody li + li {
  margin-top: 6px;
}

.markdownBody a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.markdownBody code {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  background: #f6f1e7;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.tableWrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 12px;
}

.markdownBody table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.72);
  font-size: 14px;
}

.markdownBody th,
.markdownBody td {
  border-bottom: 1px solid var(--line);
  padding: 9px 11px;
  text-align: left;
  vertical-align: top;
}

.markdownBody th {
  background: #f6f1e7;
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
}

.markdownBody tr:last-child td {
  border-bottom: 0;
}

.markdownBody sup {
  color: var(--accent-strong);
  font-size: 0.72em;
  font-weight: 800;
}

.sourceLine {
  display: grid;
  gap: 4px;
  border-top: 1px solid var(--line);
  padding-top: 9px;
  color: var(--muted);
  font-size: 13px;
}

.sourceLine span {
  color: var(--accent-strong);
  font-weight: 800;
}

.streamStatus {
  color: var(--muted);
  font-size: 13px;
}

.toolSteps {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.toolStep {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: #fbf7ee;
  color: var(--muted);
  font-size: 13px;
}

.toolStep::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  align-self: center;
}

.toolStep.done::before {
  background: #4f7c4a;
}

.toolStep strong {
  color: var(--ink);
}

.toolStep span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.streamAnswer {
  margin-top: 12px;
}

.composerShell {
  padding: 14px clamp(18px, 6vw, 76px) 20px;
  border-top: 1px solid var(--line);
  background: rgba(251, 250, 246, 0.96);
  backdrop-filter: blur(10px);
}

.fileList {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.fileLabel,
.fileList a {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}

.fileList a:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.composer textarea {
  border: 0;
  padding: 10px 8px;
  background: transparent;
}

.composer textarea:focus {
  outline: none;
}

.filePicker {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface-soft);
  cursor: pointer;
  font-weight: 700;
}

.filePicker:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.filePicker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

#sendButton {
  background: var(--accent);
}

#sendButton:hover {
  background: var(--accent-strong);
}

#sendButton:disabled {
  opacity: 0.55;
  cursor: wait;
}

@media (max-width: 820px) {
  .appShell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    height: auto;
    min-height: 0;
    max-height: 232px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 250, 244, 0.14);
  }

  .brandRow {
    padding: 12px 14px;
  }

  .brandRow h1 {
    font-size: 18px;
  }

  .sessionList {
    display: flex;
    gap: 8px;
    min-height: 0;
    height: 74px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 10px;
  }

  .sessionItem {
    min-width: 210px;
    padding: 0;
  }

  .sessionItem + .sessionItem {
    margin-top: 0;
  }

  .sidebarFooter {
    padding: 8px 10px 10px;
  }

  .chatShell {
    height: auto;
    min-height: 0;
  }

  .chatHeader {
    padding: 13px 16px;
  }

  .chatHeader h2,
  .chatHeader p {
    max-width: 100%;
    white-space: normal;
  }

  .messageList,
  .composerShell {
    padding-left: 16px;
    padding-right: 16px;
  }

  .message {
    display: flex;
  }

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