:root {
  --ink: #202124;
  --muted: #68707c;
  --line: #d7d8d2;
  --paper: #f8f7f1;
  --panel: #ffffff;
  --green: #246b56;
  --red: #b23b3b;
  --blue: #2f5f8f;
  --ochre: #b8822f;
  --shadow: 0 18px 45px rgba(37, 39, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(32, 33, 36, 0.04) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(180deg, rgba(32, 33, 36, 0.035) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--paper);
  font-family: "Aptos", "Segoe UI", "Microsoft YaHei", sans-serif;
}

button,
textarea {
  font: inherit;
}

.workspace {
  display: grid;
  grid-template-columns: 260px minmax(460px, 1fr) 360px;
  min-height: 100vh;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.58);
}

.brand {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border: 2px solid var(--ink);
  background:
    linear-gradient(135deg, transparent 42%, var(--ochre) 42% 56%, transparent 56%),
    linear-gradient(90deg, var(--panel) 0 48%, var(--green) 48% 56%, var(--panel) 56%);
  box-shadow: 5px 5px 0 var(--ink);
}

.brand-title {
  font-family: Georgia, "Times New Roman", "SimSun", serif;
  font-size: 18px;
  line-height: 1.05;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.prompt-bank {
  display: grid;
  gap: 8px;
}

.prompt,
.ghost-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 38px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.prompt {
  text-align: left;
  padding: 0 12px;
}

.prompt:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
  border-color: var(--ink);
}

.prompt.active {
  border-color: var(--ink);
  background: #f0e4cf;
}

.system-status {
  margin-top: auto;
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.system-status div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.system-status span {
  color: var(--muted);
}

.chat-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  background: rgba(255, 255, 255, 0.36);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.source-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", "SimSun", serif;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
}

.topbar p,
.source-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.ghost-btn {
  padding: 0 14px;
  min-width: 72px;
}

.messages {
  overflow: auto;
  padding: 26px 28px;
}

.message {
  display: grid;
  gap: 8px;
  max-width: 820px;
  margin-bottom: 18px;
}

.message.user {
  margin-left: auto;
  justify-items: end;
}

.role {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.bubble {
  width: fit-content;
  max-width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(37, 39, 42, 0.06);
  line-height: 1.72;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: #20302b;
  color: #fff;
  border-color: #20302b;
}

.cite-token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  margin: 0 2px;
  padding: 0 6px;
  border: 1px solid var(--blue);
  border-radius: 5px;
  color: var(--blue);
  background: #eef4f8;
  cursor: pointer;
  font-size: 12px;
}

.cite-token:hover {
  background: var(--blue);
  color: #fff;
}

.composer {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 10px;
  padding: 18px 28px 24px;
  border-top: 1px solid var(--line);
}

.composer textarea {
  width: 100%;
  min-height: 54px;
  max-height: 160px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px 13px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.composer textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 95, 143, 0.12);
}

.composer button {
  border: 1px solid #193027;
  border-radius: 7px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
}

.composer button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.source-pane {
  display: grid;
  grid-template-rows: auto minmax(160px, 38vh) 1fr;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  min-width: 0;
}

.source-head {
  padding: 24px 22px 18px;
  border-bottom: 1px solid var(--line);
}

.source-list {
  overflow: auto;
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.source-item {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--panel);
  cursor: pointer;
}

.source-item:hover,
.source-item.active {
  border-color: var(--blue);
  box-shadow: 0 10px 24px rgba(47, 95, 143, 0.12);
}

.source-index {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 5px;
  background: #eef4f8;
  color: var(--blue);
  font-weight: 700;
}

.source-title {
  font-weight: 700;
  line-height: 1.35;
}

.source-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.source-preview {
  overflow: auto;
  padding: 18px 20px 24px;
}

.preview-title {
  margin: 0 0 8px;
  font-family: Georgia, "Times New Roman", "SimSun", serif;
  font-size: 20px;
}

.preview-meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
}

.excerpt {
  margin: 0;
  padding: 15px;
  border-left: 4px solid var(--ochre);
  background: #fffaf0;
  line-height: 1.75;
}

.pdf-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 12px;
  margin-top: 14px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  background: var(--panel);
}

.empty-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: var(--muted);
}

.page-lines {
  width: 120px;
  height: 150px;
  padding: 22px 18px;
  border: 2px solid var(--ink);
  background: var(--panel);
  box-shadow: 8px 8px 0 var(--ochre);
}

.page-lines span {
  display: block;
  height: 8px;
  margin-bottom: 12px;
  background: var(--line);
}

.page-lines span:nth-child(2) {
  width: 78%;
}

.page-lines span:nth-child(3) {
  width: 92%;
  background: #b8c9d6;
}

.page-lines span:nth-child(4) {
  width: 58%;
}

.error {
  color: var(--red);
  border-color: rgba(178, 59, 59, 0.32);
  background: #fff1f1;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 220px minmax(420px, 1fr);
  }

  .source-pane {
    grid-column: 1 / -1;
    grid-template-rows: auto auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .source-list {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }
}

@media (max-width: 760px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .prompt-bank {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .prompt {
    text-align: center;
    padding: 0 6px;
  }

  .topbar,
  .messages,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer button {
    height: 42px;
  }
}

