:root {
  color-scheme: light;
  --ink: #22201d;
  --ink-soft: #756f66;
  --paper: #f7f6f2;
  --paper-warm: #fcfbf8;
  --panel: #ffffff;
  --panel-strong: #fffdf9;
  --line: rgba(34, 32, 29, 0.10);
  --line-strong: rgba(34, 32, 29, 0.18);
  --sage: #9a9a8f;
  --sage-deep: #5f5c54;
  --moss: #26231f;
  --clay: #8b6f4e;
  --gold: #d6c2a5;
  --sky: #ebe8df;
  --danger: #9f2d24;
  --shadow-soft: 0 18px 60px rgba(34, 32, 29, 0.08);
  --shadow-card: 0 12px 34px rgba(34, 32, 29, 0.08);
  font-family: Inter, "Aptos", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--paper);
}

.loginBody { overflow: auto; }

button, textarea, input { font: inherit; }

button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf9;
  color: var(--ink);
  padding: 8px 12px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease, opacity 140ms ease;
}

button:hover:not(:disabled) {
  background: #f0eee8;
  border-color: var(--line-strong);
}

button:disabled { opacity: 0.5; cursor: not-allowed; }

.appShell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  background: var(--paper);
}

.sidebar {
  min-height: 0;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 10px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #e8e3d8;
  transition: width 180ms ease, padding 180ms ease;
}

.sidebar.collapsed {
  width: 64px;
  padding: 12px 8px;
  overflow-x: hidden;
}

.sidebar.collapsed .brandCopy,
.sidebar.collapsed .viewNav,
.sidebar.collapsed .sidebarSessions,
.sidebar.collapsed .sidebarFooter,
.sidebar.collapsed .newProjectButton,
.sidebar.collapsed .sidebarProjectList {
  display: none;
}

.brandPanel {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 34px;
}

.brandMark {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: #f9f7f1;
  font-size: 14px;
  font-weight: 800;
  background: var(--moss);
}

.iconButton {
  margin-left: auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  padding: 0;
  color: var(--ink-soft);
  background: transparent;
}

.sidebar h1, .chatHeader strong, .workspaceHero h2, .workspacePanel h3, .welcomeCard h2 { margin: 0; letter-spacing: -0.035em; }
.sidebar h1 { font-size: 14px; line-height: 1; }
.workspacePanel h3 { font-size: 15px; }
.muted { color: var(--ink-soft); }
.smallText { font-size: 12px; }
.errorText { color: var(--danger) !important; }
[hidden], .templateOnly { display: none !important; }

.newProjectButton {
  width: 100%;
  text-align: left;
  border-color: transparent;
  background: rgba(255, 255, 255, 0.48);
  font-weight: 700;
}

.sidebarProjectList {
  display: grid;
  gap: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(34, 32, 29, 0.08);
}
.sidebarProjectButton {
  width: 100%;
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 7px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebarProjectButton.active,
.sidebarProjectButton:hover { background: rgba(255, 255, 255, 0.46); }
.sidebarEmpty { margin: 2px 8px 6px; }

.viewNav { display: grid; gap: 4px; }
.viewNav button, .projectShortcut {
  width: 100%;
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 7px 8px;
}
.viewNav button.active, .projectShortcut:hover { background: rgba(255, 255, 255, 0.46); }

.sidebarSessions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
}
.sidebarSectionTitle { margin: 8px 7px 2px; color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.sessionChip { display: flex; align-items: center; gap: 7px; padding: 7px 8px; border-radius: 10px; background: rgba(255, 255, 255, 0.36); }
.sessionDot { width: 6px; height: 6px; border-radius: 999px; background: #25a45c; }
.state { min-width: 0; color: var(--ink); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contextHint { margin: 4px 8px 8px; color: var(--ink-soft); font-size: 12px; line-height: 1.45; }
.sidebarFooter { margin-top: auto; padding: 10px 8px; border-top: 1px solid rgba(34, 32, 29, 0.08); color: var(--ink-soft); font-size: 12px; }
.logoutButton {
  width: 100%;
  margin-top: 8px;
  padding: 6px 8px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.34);
}

.mainStage {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: var(--paper);
}

.chatHeader {
  min-height: 54px;
  padding: 12px 28px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.chatHeader strong { display: block; font-size: 14px; font-weight: 700; }
.panelEyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.statusBadge {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdf9;
  color: var(--ink-soft);
  padding: 6px 10px;
  font-size: 12px;
}

.workspaceView { min-height: 0; overflow: auto; padding: 0 42px 24px; }
.projectWorkspace, .knowledgeWorkspace { min-height: 0; }
.workspaceHero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin: 56px auto 18px;
  max-width: 940px;
}
.compactHero {
  margin: 34px auto 12px;
  align-items: center;
}
.workspaceHero h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(34px, 5vw, 52px);
  font-weight: 500;
  line-height: 1;
}
.workspaceHero p { max-width: 620px; line-height: 1.6; }

.workspaceGrid {
  max-width: 1040px;
  margin: 0 auto 14px;
  display: grid;
  grid-template-columns: minmax(240px, 0.52fr) minmax(360px, 1.48fr);
  gap: 12px;
  align-items: start;
}

.splitPanels {
  max-width: 940px;
  margin: 0 auto 14px;
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(280px, 1.05fr);
  gap: 12px;
  align-items: start;
}

.panel, .workspacePanel {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 253, 249, 0.92);
  box-shadow: 0 8px 24px rgba(34, 32, 29, 0.04);
}

.panelHeaderRow { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.projectHome, .projectDetailEditor, .detailPanel, .currentSessionPanel { max-width: 940px; margin: 12px auto 0; }
.projectPage {
  max-width: 960px;
  margin: 0 auto 24px;
  display: grid;
  gap: 14px;
  border-color: transparent;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}
.projectPage .projectHome,
.projectPage .projectDetailEditor,
.projectPage .detailPanel,
.projectPage .currentSessionPanel { max-width: none; margin: 0; }
.projectList, .documentList { display: flex; flex-direction: column; gap: 8px; }
.documentList { margin-top: 10px; }

.projectDialog {
  width: min(460px, calc(100vw - 32px));
  border: 0;
  border-radius: 20px;
  padding: 0;
  background: transparent;
  color: var(--ink);
}
.projectDialog::backdrop { background: rgba(34, 32, 29, 0.24); backdrop-filter: blur(2px); }
.dialogCard {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  background: #fffdf9;
  box-shadow: var(--shadow-soft);
}
.dialogCard h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 32px; font-weight: 500; }
.dialogCard p { margin: 6px 0 0; }
.dialogCard label { display: grid; gap: 6px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.dialogCard input {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf9;
  color: var(--ink);
  outline: none;
  padding: 10px;
}
.dialogActions { justify-content: flex-end; }

.projectTabs {
  display: inline-flex;
  gap: 18px;
  width: fit-content;
  border-bottom: 1px solid var(--line);
}
.projectTabs button {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-soft);
  padding: 0 0 9px;
}
.projectTabs button.active,
.projectTabs button[aria-selected="true"] {
  background: transparent;
  box-shadow: none;
  color: var(--ink);
  border-bottom: 2px solid var(--ink);
}
.projectDetailsPane, .projectChatPane { display: grid; gap: 16px; }
.sessionHeaderRow { margin-bottom: 0; }
.projectSessionList { display: grid; gap: 8px; }
.projectSessionCard {
  display: grid;
  gap: 4px;
  width: 100%;
  text-align: left;
  border-radius: 14px;
  background: #fffdf9;
}
.projectSessionCard strong,
.projectSessionCard span,
.projectSessionCard small { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.projectSessionCard span,
.projectSessionCard small { color: var(--ink-soft); font-size: 12px; }
.projectSessionCard.active { border-color: var(--line-strong); box-shadow: var(--shadow-card); }
.knowledgeWorkspace { max-width: 940px; margin: 0 auto; }
.knowledgeWorkspace .workspaceHero { margin-left: 0; margin-right: 0; }
.projectCard {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf9;
  padding: 12px;
}
.projectCard.selected { border-color: var(--line-strong); box-shadow: var(--shadow-card); }
.projectCard strong, .projectCard span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.projectCard span, .projectCard p { color: var(--ink-soft); margin: 0; font-size: 12px; line-height: 1.45; }

.projectDisclosure {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf9;
  overflow: hidden;
}
.projectDisclosure.selected { border-color: var(--line-strong); }
.projectDisclosure.expanded { box-shadow: var(--shadow-card); }
.projectDisclosureSummary {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  padding: 12px;
}
.projectDisclosureSummary span:first-child { min-width: 0; display: grid; gap: 3px; }
.projectDisclosureSummary strong, .projectDisclosureSummary small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.projectDisclosureSummary small { color: var(--ink-soft); }
.projectDisclosureChevron { color: var(--ink-soft); font-weight: 700; }
.projectDisclosureBody { padding: 0 12px 12px; border-top: 1px solid var(--line); }
.compactActions { margin-top: 8px; }

.fileDrop {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 10px 0 8px;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  background: #faf8f1;
  color: var(--ink);
  cursor: pointer;
}
.fileDrop span { font-weight: 700; }
.fileDrop small { color: var(--ink-soft); line-height: 1.35; }
.compactDrop { margin-top: 0; }
.fileInput { width: 100%; color: var(--ink-soft); font-size: 12px; }

.documentCard {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf9;
  padding: 10px;
}
.documentCard strong, .documentCard span { display: block; font-size: 13px; }
.documentCard span, .documentCard p { color: var(--ink-soft); margin: 5px 0 0; font-size: 12px; line-height: 1.45; }

.projectForm { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.projectForm label { display: flex; flex-direction: column; gap: 5px; color: var(--ink); font-size: 13px; font-weight: 600; }
.projectForm .projectDetailsLabel, .projectForm .formActions, .projectForm #projectFormStatus { grid-column: 1 / -1; }
.projectForm input, .projectForm textarea, .searchRow input {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf9;
  color: var(--ink);
  outline: none;
  padding: 11px 12px;
}
.projectForm textarea { width: 100%; max-height: none; resize: vertical; }
.projectUploadRow {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  align-items: center;
}
.formActions, .detailActions, .uploadRow, .searchRow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.formActions button, .detailActions button, .uploadRow button { flex: 0 1 auto; }
.searchRow { align-items: stretch; margin-top: 10px; }
.searchRow input { flex: 1 1 160px; }
.ghostButton { background: transparent; color: var(--ink); }
.dangerButton { color: var(--danger); border-color: rgba(159, 45, 36, 0.18); }
.smallButton { padding: 6px 9px; margin-top: 8px; font-size: 12px; }

.detailEmpty, .emptyState { padding: 18px; border-radius: 14px; background: #faf8f1; color: var(--ink-soft); text-align: center; }
.detailHeader { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; margin-bottom: 10px; }
.detailHeader h3 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 32px; font-weight: 500; }
.detailGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.detailBlock { padding: 12px; border-radius: 12px; background: #faf8f1; border: 1px solid var(--line); }
.detailBlock strong { display: block; margin-bottom: 7px; }
.detailBlock p { margin: 0; color: var(--ink-soft); line-height: 1.55; white-space: pre-wrap; }
.projectKnowledgeCard, .sessionEntry {
  padding: 14px 0 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
}
.sessionEntry { margin-top: 10px; }

.chat {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  padding: 0 28px 24px;
}
.chatStage { min-height: 0; display: grid; grid-template-rows: auto minmax(0, auto) minmax(0, 1fr); max-width: 940px; width: 100%; margin: 0 auto; padding: 0; }
.activity { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 0 10px; overflow-x: auto; }
.activity:empty { display: none; }
.activityStep { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 999px; background: #fffdf9; color: var(--ink-soft); padding: 5px 9px; font-size: 12px; }
.activityStep.ok { background: #f3f1eb; }
.activityStep.running { background: #fff7df; }
.activityStep.blocked { background: #fff7df; }
.activityStep.failed { background: #fff2ee; }
.statusPill { color: var(--ink-soft); font-size: 11px; }
.stepError { color: var(--danger); }

.welcomeCard {
  justify-self: center;
  align-self: center;
  width: min(720px, 100%);
  margin: 116px auto 22px;
  border: 0;
  border-radius: 18px;
  padding: 18px;
  background: transparent;
  text-align: center;
}
.welcomeKicker { color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.welcomeCard h2 { margin-top: 6px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(34px, 5vw, 48px); font-weight: 500; line-height: 1.05; }
.welcomeCard p { max-width: 600px; margin: 10px auto 0; color: var(--ink-soft); font-size: 14px; line-height: 1.7; }
.messages { min-height: 0; overflow-y: auto; padding: 12px 0 20px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.message { max-width: min(760px, 86%); border-radius: 18px; padding: 12px 14px; line-height: 1.62; white-space: pre-wrap; animation: bubbleIn 180ms ease both; }
.message.student { align-self: flex-end; border-bottom-right-radius: 6px; background: var(--moss); color: #fffdf9; box-shadow: 0 10px 26px rgba(34, 32, 29, 0.15); }
.message.agent { align-self: flex-start; border: 1px solid var(--line); border-bottom-left-radius: 6px; background: #fffdf9; }
.message.pending { color: var(--ink-soft); background: rgba(255, 253, 249, 0.62); border-style: dashed; }
.message.error { color: var(--danger); background: #fff2ee; border-color: rgba(159, 45, 36, 0.24); }
.message.system { align-self: center; background: transparent; color: var(--ink-soft); font-size: 13px; padding: 4px 8px; }

.composer { max-width: 940px; width: 100%; margin: 0 auto; }
.composerBox {
  position: relative;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 10px;
  background: #fffdf9;
  box-shadow: 0 12px 32px rgba(34, 32, 29, 0.08);
  overflow: visible;
}
.composerBox::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 0; background: var(--gold); }
.composerBox:focus-within { border-color: rgba(34, 32, 29, 0.28); }
.composerInputRow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.composerActionWrap { position: relative; }
.composerActionButton {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  padding: 0;
  background: #f4f1e9;
  color: var(--ink);
  font-size: 18px;
}
.chatActionMenu {
  position: absolute;
  left: 0;
  bottom: 40px;
  min-width: 138px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf9;
  box-shadow: var(--shadow-card);
  z-index: 4;
}
.chatActionMenu button { width: 100%; text-align: left; border-color: transparent; background: transparent; }
.composerFooter { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 7px; padding-left: 40px; }
.composerHint { color: var(--ink-soft); font-size: 12px; }
textarea { width: 100%; resize: none; border: 0; border-radius: 10px; padding: 7px 4px; outline: none; max-height: 180px; background: transparent; color: var(--ink); }
textarea::placeholder, input::placeholder { color: rgba(117, 111, 102, 0.68); }

.loginShell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.loginCard {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 26px;
  background: #fffdf9;
  box-shadow: var(--shadow-soft);
}
.loginCard h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 7vw, 42px);
  font-weight: 500;
  line-height: 1.05;
}
.loginCard p { margin: 0; line-height: 1.55; }
.loginForm { display: grid; gap: 12px; }
.loginForm label { display: grid; gap: 6px; color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.loginForm input {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf9;
  color: var(--ink);
  outline: none;
  padding: 11px 12px;
}
.loginForm button { width: 100%; justify-content: center; }

@keyframes bubbleIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1080px) {
  body { overflow: auto; }
  .appShell { min-height: 100vh; min-height: 100dvh; height: auto; grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar.collapsed { width: auto; }
  .mainStage { min-height: 78vh; }
  .workspaceHero { margin-top: 28px; }
  .splitPanels, .workspaceGrid, .detailGrid, .projectForm { grid-template-columns: 1fr; }
  .messages { padding: 12px 0 18px; }
  .message { max-width: 92vw; }
  .activity { flex-wrap: nowrap; }
  .welcomeCard { margin-top: 42px; }
  .composer { position: sticky; bottom: 0; }
  .composerHint { display: none; }
}
