:root {
  color-scheme: light;
  --bg: #f7f3ef;
  --panel: #fffaf6;
  --panel-strong: #ffffff;
  --text: #2f2824;
  --muted: #7a6e67;
  --line: #eadfd6;
  --accent: #9d6b55;
  --accent-dark: #764c3c;
  --danger: #9f3d3d;
  --shadow: 0 18px 50px rgba(63, 45, 34, 0.13);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(circle at top left, #fff7f0, var(--bg) 48%, #efe7df);
  color: var(--text);
  /* Desktop: lock to one viewport; only the message list scrolls (see .messages). Mobile
     reverts to normal page scroll in the media query below. */
  height: 100vh;
  overflow: hidden;
}
button, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 300px 300px minmax(0, 1fr);
  gap: 18px;
  height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px;
}
.sidebar { overflow-y: auto; }

/* The conversation-list column (own column, between the sidebar and the chat). */
.conv-column {
  height: calc(100vh - 36px);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}
.conv-column .conv-list {
  flex: 1;             /* fill the column; the list scrolls internally */
  max-height: none;
}

.sidebar, .conv-column, .chat-panel {
  background: rgba(255, 250, 246, 0.9);
  border: 1px solid rgba(234, 223, 214, 0.9);
  border-radius: 26px;
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 42px; height: 42px; border-radius: 16px;
  display: grid; place-items: center;
  background: #efe2d8;
  color: var(--accent-dark);
  font-size: 22px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 20px; }
h2 { font-size: 18px; }
.brand p, .chat-header p, .hint, .privacy-note { color: var(--muted); font-size: 13px; line-height: 1.5; }

.secondary-btn, .danger-btn, .quick-prompts button, #sendBtn, .image-btn {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: var(--panel-strong);
  color: var(--text);
}
.secondary-btn:hover, .quick-prompts button:hover, .image-btn:hover { border-color: var(--accent); }
.danger-btn { color: var(--danger); }

.setting-block { display: grid; gap: 7px; }
.setting-block label, .toggle-row { color: var(--muted); font-size: 13px; }
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: white;
  padding: 10px 12px;
  color: var(--text);
}
.toggle-row { display: flex; align-items: center; gap: 8px; }
.session-card {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  background: rgba(255,255,255,.55);
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.session-card code { color: var(--text); word-break: break-all; }

.chat-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  height: calc(100vh - 36px);
  overflow: hidden;
}
/* The scrollable message region (grid row 1fr). Wraps #messages + the right-side nav rail. */
.messages-wrap { position: relative; min-height: 0; overflow: hidden; }
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}
.status-badge {
  white-space: nowrap;
  padding: 7px 11px;
  border-radius: 999px;
  background: #efe2d8;
  color: var(--accent-dark);
  font-size: 12px;
}
.status-badge.error { background: #f8dddd; color: var(--danger); }
.status-badge.loading { background: #eee9ff; color: #594b91; }

.messages {
  height: 100%;
  overflow-y: auto;
  padding: 24px 34px 24px 22px;   /* extra right padding to clear the nav rail */
  display: flex;
  flex-direction: column;
  gap: 22px;                       /* room below each bubble for the hover action bar */
}
.message {
  position: relative;
  max-width: min(720px, 92%);
  padding: 13px 15px;
  border-radius: 20px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-text { white-space: pre-wrap; word-break: break-word; }

/* Hover action bar (copy / edit), tucked just below each bubble. */
.msg-actions {
  position: absolute;
  bottom: -19px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s ease;
  z-index: 2;
}
.message.user .msg-actions { right: 2px; }
.message.assistant .msg-actions { left: 2px; }
.message:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.msg-actions button {
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  border: none;
  padding: 2px 7px;
  border-radius: 8px;
  line-height: 1.4;
}
.msg-actions button:hover { background: rgba(120,110,100,0.14); color: var(--text); }

/* Edit-and-resend mode: the user bubble becomes an editable box. */
.message.editing { max-width: min(720px, 92%); width: 92%; background: var(--accent-dark); }
.edit-box {
  width: 100%;
  min-height: 44px;
  resize: none;
  border: none;
  border-radius: 12px;
  padding: 9px 11px;
  line-height: 1.5;
  outline: none;
  color: var(--text);
  background: white;
}
.edit-actions { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }
.edit-actions button {
  font-size: 13px; padding: 5px 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.35); background: transparent; color: white;
}
.edit-actions .edit-send { background: white; color: var(--accent-dark); border-color: white; }

/* Brief highlight when jumping to a message from the nav rail. */
.message.jump-flash { box-shadow: 0 0 0 3px rgba(157,107,85,0.5); }

/* Per-answer feedback (👎 → tags + comment form). */
.fb-note { margin-top: 8px; font-size: 12px; color: var(--muted); }
.fb-form {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff7f1;
}
.fb-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.fb-tag {
  font-size: 12px;
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
}
.fb-tag.on { background: var(--accent); color: white; border-color: var(--accent); }
.fb-comment {
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  line-height: 1.5;
  outline: none;
  background: white;
  color: var(--text);
}
.fb-comment:focus { border-color: var(--accent); }
.fb-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.fb-actions button {
  font-size: 13px; padding: 5px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: white; color: var(--text);
}
.fb-actions .fb-submit { background: var(--accent); color: white; border-color: var(--accent); }
.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 7px;
}
.message.assistant {
  align-self: flex-start;
  background: white;
  border: 1px solid var(--line);
  border-bottom-left-radius: 7px;
}
.message.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 4px 8px;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 22px 12px;
}
.quick-prompts button { font-size: 13px; padding: 8px 10px; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 22px 10px;
  border-top: 1px solid var(--line);
  background: rgba(255,250,246,.95);
}
.image-btn { white-space: nowrap; }
.image-btn input { display: none; }
.image-preview {
  max-width: 140px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: white;
}
textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 11px 13px;
  line-height: 1.5;
  outline: none;
  background: white;
  color: var(--text);
}
textarea:focus { border-color: var(--accent); }
#sendBtn {
  min-width: 78px;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
#sendBtn:disabled { opacity: .55; cursor: not-allowed; }
.privacy-note { padding: 0 22px 16px; }

/* --- Right-side question navigator (like the ChatGPT minimap): one tick per user question,
      hover shows a preview, click scrolls to it. --- */
.msg-nav {
  position: absolute;
  top: 0; right: 4px; bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  gap: 7px;
  padding: 10px 0;
  pointer-events: none;   /* only the ticks are interactive */
  overflow: visible;      /* let the hover preview tooltip escape leftward */
}
.nav-tick {
  position: relative;
  width: 15px; height: 3px;
  padding: 0; border: none;
  border-radius: 3px;
  background: var(--line);
  pointer-events: auto;
  transition: width 0.12s ease, background 0.12s ease;
}
.nav-tick:hover { width: 22px; background: var(--accent); }
.nav-tick.active { width: 22px; background: var(--accent); }
.nav-tip {
  position: absolute;
  right: 24px; top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden; text-overflow: ellipsis;
  background: var(--text);
  color: white;
  font-size: 12px;
  padding: 5px 9px;
  border-radius: 9px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.12s ease;
  box-shadow: var(--shadow);
}
.nav-tick:hover .nav-tip { opacity: 1; }

@media (max-width: 820px) {
  /* Mobile: revert to normal page scroll (no fixed viewport), stack chat → list → settings. */
  body { height: auto; overflow: auto; }
  .app-shell { grid-template-columns: 1fr; height: auto; padding: 10px; gap: 10px; }
  .chat-panel { height: auto; min-height: 72vh; border-radius: 20px; order: 0; }
  .conv-column { height: auto; overflow: visible; border-radius: 20px; order: 2; }
  .conv-column .conv-list { max-height: 40vh; flex: none; }
  .sidebar { order: 3; border-radius: 20px; overflow: visible; }
  .message { max-width: 96%; }
  .composer { padding: 10px; }
  .chat-header { padding: 16px; }
  .messages { padding: 16px; }
  .quick-prompts { padding: 0 16px 10px; }
  .msg-nav { display: none; }   /* the minimap is a desktop affordance */
}

/* --- Conversation list: one white card, rows split by dividers --- */
.conv-list {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;          /* clip the active-row highlight to the rounded corners */
  max-height: 46vh;
  overflow-y: auto;
  margin: 2px 0 8px;
}
.conv-empty { color: var(--muted); font-size: 13px; padding: 14px; text-align: center; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 11px 12px;
  cursor: pointer;
  color: var(--text);
  background: transparent;                 /* white (the card) when idle */
  border-bottom: 1px solid var(--line);    /* horizontal divider between conversations */
  transition: background 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.conv-item:last-child { border-bottom: none; }
.conv-item:hover { background: rgba(157, 107, 85, 0.06); }
.conv-item.active { background: rgba(157, 107, 85, 0.15); }   /* selected = the accent tint */
.conv-item:active { background: rgba(157, 107, 85, 0.22); }   /* press feedback */
.conv-title {
  flex: 1;                    /* pushes the actions to the far right */
  min-width: 0;
  font-size: 14px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item.active .conv-title { font-weight: 600; }
.conv-actions { display: flex; gap: 0; flex-shrink: 0; opacity: 0; transition: opacity 0.12s ease; }
.conv-item:hover .conv-actions, .conv-item.active .conv-actions { opacity: 1; }
.conv-actions button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  padding: 4px 5px;
  border-radius: 6px;
  transition: color 0.12s ease;
}
.conv-actions button:hover { color: var(--text); }
.conv-actions button.del:hover { color: var(--danger); }

/* --- Process disclosure: a bare chevron that blends into the bubble (no label, no box) --- */
.process { margin-bottom: 2px; }
.process-toggle {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.process-toggle:hover { color: var(--text); }
.process-toggle .chev {
  display: inline-block;
  font-size: 13px;
  transition: transform 0.14s ease;
}
.process-toggle.open .chev { transform: rotate(90deg); }
.process-body { margin: 4px 0 2px; }        /* no border, no fill — one with the bubble */
.process-preamble {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  margin-bottom: 6px;
}
.process-preamble:empty { display: none; }
.process-tools { display: flex; flex-wrap: wrap; gap: 10px; }
.tool-chip { font-size: 12px; color: var(--muted); }   /* plain muted text, no pill */
.stream-status { opacity: 0.55; font-size: 13px; }
