:root {
  color-scheme: light;
  --paper: #f7f2ea;
  --surface: #fffdf9;
  --surface-2: #fff7ed;
  --ink: #24211e;
  --muted: #72675d;
  --line: #ded3c6;
  --rose: #9f415c;
  --teal: #2f7771;
  --gold: #9a6c23;
  --danger: #9b342f;
  --sidebar: #eee6db;
  --shadow: 0 18px 48px rgba(45, 36, 28, 0.1);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-layout {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  padding: calc(16px + env(safe-area-inset-top)) 12px 12px;
}

.sidebar-head,
.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

.new-chat-button {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
}

.thread-list {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  padding-right: 2px;
}

.thread-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.thread-item.is-active {
  border-color: var(--line);
  background: rgba(255, 253, 249, 0.78);
}

.thread-title {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 5px;
  font-size: 14px;
  line-height: 1.35;
}

.thread-time {
  color: var(--muted);
  font-size: 12px;
}

.main-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: var(--paper);
  padding: calc(14px + env(safe-area-inset-top)) 18px calc(14px + env(safe-area-inset-bottom));
}

.chat-topbar {
  padding-bottom: 10px;
}

.status-pill {
  min-width: 86px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 8px 10px;
  text-align: center;
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.is-ready {
  border-color: rgba(47, 119, 113, 0.35);
  color: var(--teal);
}

.status-pill.is-missing {
  border-color: rgba(155, 52, 47, 0.3);
  color: var(--danger);
}

.mode-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}

.mode-strip::-webkit-scrollbar {
  display: none;
}

.mode-button {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 0 12px;
  white-space: nowrap;
}

.mode-button.is-active {
  border-color: var(--rose);
  color: var(--ink);
  background: #fff3f5;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 8px max(0px, calc((100% - 820px) / 2)) 18px;
}

.message {
  max-width: min(820px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 13px;
}

.message.user {
  align-self: flex-end;
  width: fit-content;
  max-width: min(680px, 92%);
  background: var(--surface-2);
}

.message.assistant,
.message.system {
  align-self: flex-start;
  width: min(820px, 100%);
}

.message.system {
  background: #f4fbf8;
  border-color: rgba(47, 119, 113, 0.24);
}

.message-role {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.68;
  font-size: 15px;
}

.thinking-box {
  display: none;
  margin: 0 0 10px;
  border: 1px solid rgba(47, 119, 113, 0.24);
  border-radius: 8px;
  background: #f4fbf8;
  color: var(--muted);
}

.message.assistant .thinking-box.has-content {
  display: block;
}

.thinking-box summary {
  cursor: pointer;
  padding: 9px 10px;
  color: var(--teal);
  font-size: 13px;
}

.thinking-text {
  border-top: 1px solid rgba(47, 119, 113, 0.18);
  padding: 9px 10px 10px;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 13px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  width: min(820px, 100%);
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.96);
  padding: 8px;
  box-shadow: var(--shadow);
}

textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  padding: 8px 4px;
  line-height: 1.5;
}

#sendButton {
  min-width: 68px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
  padding: 0 14px;
}

#sendButton:disabled {
  cursor: progress;
  opacity: 0.58;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.mobile-only {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 10;
  transform: translateX(-50%) translateY(14px);
  max-width: min(92vw, 420px);
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 760px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(86vw, 320px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-grid;
    place-items: center;
  }

  .main-panel {
    padding-inline: 12px;
  }

  .messages {
    padding-inline: 0;
  }

  h2 {
    font-size: 18px;
  }
}
