:root {
  --ink: #13221d;
  --mute: #5d6f68;
  --line: rgba(19, 34, 29, 0.12);
  --paper: #fffaf2;
  --panel: #ffffff;
  --brand: #0b6b5c;
  --brand-2: #085247;
  --accent: #c45c26;
  --accent-soft: #f3e0d2;
  --mint: #d9efe8;
  --ok: #0f766e;
  --bad: #b42318;
  --shadow: 0 20px 60px rgba(16, 40, 34, 0.12);
  --sans: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --serif: "Songti SC", "STSong", "SimSun", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: #e8eee9;
}

/* author display must not override [hidden] */
[hidden] { display: none !important; }

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1000px 520px at -10% -20%, rgba(11, 107, 92, 0.28), transparent 60%),
    radial-gradient(800px 480px at 110% 0%, rgba(196, 92, 38, 0.18), transparent 55%),
    linear-gradient(160deg, #dce8e2 0%, #f0ebe3 48%, #e7e2d8 100%);
}

.mark {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--brand-2);
}

/* -------- login -------- */
.login-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 28px 26px 24px;
  animation: rise 0.5s ease both;
}
.login-brand .mark { font-size: 34px; }
.login-brand h1 {
  margin: 10px 0 8px;
  font-family: var(--serif);
  font-size: 28px;
}
.login-lead { margin: 0; color: var(--mute); line-height: 1.6; font-size: 14px; }
.login-form { margin-top: 22px; display: grid; gap: 12px; }
.login-form label { display: grid; gap: 6px; font-size: 13px; color: var(--mute); }
.login-form input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 15px;
  background: #fff;
  color: var(--ink);
}
.login-form input:focus {
  outline: none;
  border-color: rgba(11, 107, 92, 0.55);
  box-shadow: 0 0 0 3px rgba(11, 107, 92, 0.12);
}
.login-err { margin: 0; color: var(--bad); font-size: 13px; }

.btn-primary {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-ghost {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 12px;
  color: var(--mute);
  cursor: pointer;
}
.btn-ghost:hover { color: var(--ink); border-color: rgba(11, 107, 92, 0.4); }

/* -------- app shell -------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 18px 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.brand-row { display: flex; align-items: baseline; gap: 8px; }
.brand-row .mark { font-size: 28px; }
.slash { color: var(--line); }
.product { letter-spacing: 0.28em; color: var(--mute); font-size: 13px; }
.top-meta { display: flex; align-items: center; gap: 10px; }
.chip {
  font-size: 12px;
  color: var(--brand-2);
  background: var(--mint);
  border-radius: 999px;
  padding: 5px 10px;
}
.who { font-size: 13px; color: var(--mute); }

.shell {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 18px 28px;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.side {
  background: rgba(255, 250, 242, 0.85);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  height: fit-content;
}
.side-title {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-size: 16px;
}
.tips {
  margin: 0;
  padding-left: 18px;
  color: var(--mute);
  font-size: 13px;
  line-height: 1.7;
}
.tips strong { color: var(--accent); font-weight: 600; }
.upload-mini {
  display: block;
  margin-top: 16px;
  text-align: center;
  border: 1px dashed rgba(11, 107, 92, 0.35);
  border-radius: 12px;
  padding: 10px;
  font-size: 12px;
  color: var(--brand);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.6);
}
.upload-info { margin: 8px 0 0; font-size: 12px; color: var(--mute); white-space: pre-wrap; }

.chat-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 110px);
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 20px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background:
    linear-gradient(180deg, rgba(217, 239, 232, 0.35), transparent 120px),
    #fff;
}

.msg {
  max-width: min(720px, 92%);
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.7;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise 0.35s ease both;
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  border-bottom-right-radius: 6px;
}
.msg.assistant {
  align-self: flex-start;
  background: #f6f1e8;
  border: 1px solid rgba(196, 92, 38, 0.12);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}
.msg.assistant .tag {
  display: inline-block;
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 8px;
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--mute);
  font-size: 13px;
  padding: 4px 8px;
}
.msg.busy { opacity: 0.7; }

.composer {
  border-top: 1px solid var(--line);
  padding: 12px 14px 14px;
  background: #fffcf7;
}
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font: inherit;
  font-size: 15px;
  line-height: 1.55;
  resize: none;
  min-height: 72px;
  background: #fff;
}
.composer textarea:focus {
  outline: none;
  border-color: rgba(11, 107, 92, 0.5);
  box-shadow: 0 0 0 3px rgba(11, 107, 92, 0.1);
}
.composer-bar {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.hint { font-size: 12px; color: var(--mute); }

/* conversations */
.btn-new {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 11px 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  margin-bottom: 14px;
}
.btn-new:hover { filter: brightness(1.06); }
.conv-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 46vh;
  overflow: auto;
  margin-bottom: 6px;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  border: 1px solid transparent;
}
.conv-item:hover { background: rgba(11, 107, 92, 0.06); }
.conv-item.is-on {
  background: #fff;
  border-color: rgba(11, 107, 92, 0.25);
  color: var(--brand-2);
  font-weight: 600;
}
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del {
  border: none;
  background: none;
  color: var(--mute);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--bad); }
.conv-empty { font-size: 12px; color: var(--mute); padding: 4px 2px; }
.side-tip { margin: 14px 0 0; font-size: 12px; line-height: 1.6; color: var(--mute); }
.side-tip strong { color: var(--accent); }

/* rendered markdown inside assistant bubbles */
.msg.assistant { white-space: normal; }
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.msg.assistant .body p { margin: 0 0 10px; }
.msg.assistant .body h2,
.msg.assistant .body h3,
.msg.assistant .body h4,
.msg.assistant .body h5 {
  margin: 14px 0 8px;
  font-family: var(--serif);
  color: var(--brand-2);
  line-height: 1.4;
}
.msg.assistant .body h2 { font-size: 19px; }
.msg.assistant .body h3 { font-size: 17px; }
.msg.assistant .body h4, .msg.assistant .body h5 { font-size: 15px; }
.msg.assistant .body ul, .msg.assistant .body ol { margin: 0 0 10px; padding-left: 22px; }
.msg.assistant .body li { margin: 3px 0; }
.msg.assistant .body strong { color: #0f2e27; }
.msg.assistant .body code {
  background: rgba(19, 34, 29, 0.06);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
}
.msg.assistant .body hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.msg-actions { margin-top: 8px; display: flex; gap: 10px; }
.msg-actions button {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: var(--mute);
  cursor: pointer;
}
.msg-actions button:hover { color: var(--brand); }
.cursor::after {
  content: "▍";
  margin-left: 2px;
  color: var(--brand);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.composer-btns { display: flex; gap: 8px; align-items: center; }
.composer textarea:disabled { background: #f6f4ef; }

/* selection toolbar */
.sel-bar {
  position: fixed;
  z-index: 50;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: #13221d;
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  transform: translate(-50%, calc(-100% - 10px));
}
.sel-bar button {
  border: none;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.sel-bar button:hover { background: rgba(255, 255, 255, 0.12); }
.sel-bar button[data-act="polish"] { color: #9fe7d6; }
.sel-bar button[data-act="continue"] { color: #ffd2b0; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { order: 2; }
  .chat-panel { min-height: 70vh; }
}
