:root {
  color-scheme: light;
  --bg: #e6e0d6;
  --panel: #f7f4ef;
  --ink: #221e1a;
  --muted: #74695e;
  --line: #ddd4c8;
  --accent: #1f6b4a;
  --accent-ink: #f4fff8;
  --mine: #fffdf9;
  --theirs: #e5f2ea;
  --danger: #8d3a2f;
  --warn: #8a5b16;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body, #root { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

body.user {
  display: grid;
  place-items: center;
}
body.user.blank {
  display: block;
  background: #fff;
}
body.user #root:has(> .login),
body.user.ended #root,
body.agent #root:has(> .login) {
  display: grid;
  place-items: center;
}
.restart {
  width: min(420px, calc(100% - 48px));
  margin: 24px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  justify-content: center;
}
.user-app, .login {
  width: min(760px, 100%);
  height: min(920px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.login {
  width: min(420px, calc(100% - 48px));
  height: auto;
  padding: 28px;
  gap: 18px;
  margin: 24px;
}
.login form, .login label { display: flex; flex-direction: column; gap: 8px; }
.captcha-row { display: flex; align-items: center; gap: 8px; }
.captcha-row input { flex: 1; min-width: 0; }
.captcha-row img { height: 42px; border: 1px solid var(--line); background: white; cursor: pointer; }
.login input, .login select {
  border: 1px solid var(--line);
  background: white;
  padding: 10px 12px;
}
.login .hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-title { display: flex; align-items: center; gap: 12px; }
.brand h1, .thread-head h2 { margin: 0; font-family: Palatino, "Palatino Linotype", "Songti SC", serif; font-weight: 600; }
.brand h1 { font-size: 22px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 12px; letter-spacing: 0.08em; }
.mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: Palatino, "Palatino Linotype", serif;
}

.bar, .topbar, .thread-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.user-app .bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.user-app .bar .pill { grid-column: 2; justify-self: center; }
.user-app .bar [data-end] { grid-column: 3; justify-self: end; }
.bar-side, .thread-head div:last-child { display: flex; align-items: center; gap: 8px; }
.pill {
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.pill.pending { color: var(--warn); border-color: #ead7b6; background: #fff7ea; }
.pill.active { color: var(--accent); border-color: #cfe3d6; background: var(--theirs); }
.pill.closed { color: var(--muted); }

.history {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--muted);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.history select, .primary, .ghost, .danger, .tab, .conv {
  border: 1px solid var(--line);
  background: white;
}
.history select { padding: 4px 8px; }

.thread {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.empty { margin: auto; color: var(--muted); text-align: center; }
.empty p { margin: 0; }

.msg { display: flex; }
.msg.mine { justify-content: flex-end; }
.bubble {
  max-width: min(78%, 460px);
  padding: 10px 12px;
  background: var(--theirs);
  border: 1px solid #d5e6db;
}
.msg.mine .bubble { background: var(--mine); border-color: var(--line); }
.who, .file-meta, .meta, .hint, time {
  color: var(--muted);
  font-size: 12px;
}
.who, time { display: block; }
.body { margin: 4px 0; white-space: pre-wrap; word-break: break-word; }
.file-card {
  width: 100%;
  margin-top: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  background: white;
  border: 1px solid var(--line);
}
.file-name {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview { display: block; max-width: 100%; max-height: 220px; margin-top: 8px; }

.composer, .closed-panel { padding: 12px 16px 16px; border-top: 1px solid var(--line); }
.composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 52px;
  max-height: 140px;
  border: 1px solid var(--line);
  background: white;
  padding: 8px 10px;
}
.composer-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.hint { margin-right: auto; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  background: white;
  font-size: 13px;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button, .file-btn { border: 0; background: transparent; color: var(--accent); padding: 0; }
.primary, .ghost, .danger, .tab {
  padding: 8px 12px;
}
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.danger { color: var(--danger); border-color: #e7cfcb; }
.primary:disabled { opacity: 0.6; cursor: default; }
.error { margin: 0 16px; color: var(--danger); font-size: 13px; }
.login .error { margin: 0; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(34, 30, 26, 0.28);
}
.modal .login { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  z-index: 3;
  margin: 0;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-ink);
}

.desk {
  height: 100%;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
}
.topbar { grid-column: 1 / -1; background: var(--panel); }
.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.tabs { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.tab { padding: 6px 8px; font-size: 13px; }
.tab.active { background: var(--theirs); border-color: #cfe3d6; color: var(--accent); }
.list { flex: 1; overflow: auto; min-height: 0; }
.conv-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
}
.conv {
  width: auto;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px;
  border: 0;
  background: transparent;
  text-align: left;
}
.conv-delete {
  flex: none;
  align-self: center;
  margin-right: 8px;
  padding: 4px 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
}
.conv-row:hover:not(:has(.selected)) { background: #efeae3; }
.conv-row:hover .conv-delete { border-color: #e7cfcb; background: white; }
.conv-row:has(.selected) {
  background: #cfe8db;
  box-shadow: inset 4px 0 0 var(--accent);
}
.conv.selected { background: transparent; }
.conv strong, .thread-head h2 {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv.unread strong::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  background: var(--accent);
  border-radius: 50%;
}
.preview {
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.list-empty { color: var(--muted); padding: 16px; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #fbfaf7; }
.thread-head > div:first-child { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.thread-head h2 { font-size: 20px; }
.thread-head p { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 13px; }
.conv-title {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
}
.conv-title strong { flex: 1; min-width: 0; }
.presence {
  flex: none;
  font-size: 12px;
  padding: 1px 6px;
  border: 1px solid transparent;
}
.presence.online { color: #f4fff8; background: #1f6b4a; border-color: #1f6b4a; }
.presence.offline { color: #8d3a2f; background: #f8e8e4; border-color: #e4c4be; }

@media (max-width: 800px) {
  body.user { display: block; }
  .user-app { width: 100%; height: 100%; border: 0; }
  .desk { grid-template-columns: 1fr; grid-template-rows: auto 220px minmax(0, 1fr); }
  .topbar { grid-column: auto; }
  .hint { display: none; }
}
