:root {
  color-scheme: light;
  --bg: #ededed;
  --panel: #ffffff;
  --sidebar: #f7f7f7;
  --chat-bg: #f5f5f5;
  --line: #e3e3e3;
  --line-soft: #ededed;
  --text: #1a1a1a;
  --muted: #9a9a9a;
  --muted-strong: #6b6b6b;
  --green: #07c160;
  --green-strong: #05a350;
  --bubble-own: #95ec69;
  --bubble-other: #ffffff;
  --blue: #576b95;
  --red: #d9453f;
  --selected: #d9d9d9;
  --hover: #ececec;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  /* iOS Safari ignores `overflow:hidden` for document scroll — must pin body with
     position:fixed to truly lock the viewport. Otherwise whole page pans/scrolls,
     dragging the chat header off-screen and allowing horizontal swipe. */
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
  touch-action: manipulation;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button svg,
.mark svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

h1,
h2,
p {
  margin: 0;
}

/* ---------- shell ---------- */

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  overflow: hidden;
  background: var(--panel);
}

.back-btn {
  display: none;
  width: 32px;
  min-height: 32px;
  padding: 0;
  margin-right: 2px;
  border-color: transparent;
  background: transparent;
  color: var(--muted-strong);
  flex: 0 0 auto;
}

/* ---------- sidebar ---------- */

.sidebar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.brand h1 {
  font-size: 16px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #d8f5e3;
  color: var(--green-strong);
  flex: 0 0 auto;
}

.side-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.side-actions button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted-strong);
}

.side-actions button:hover {
  background: var(--hover);
  color: var(--text);
}

.conversation-list {
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.conv-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

.conv-item:hover {
  background: var(--hover);
}

.conv-item.selected {
  background: var(--selected);
}

.pin-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}

.pin-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.conv-item:hover .pin-btn {
  opacity: 0.7;
}

.pin-btn:hover {
  opacity: 1;
  background: var(--hover);
  color: var(--text);
}

.pin-btn.active {
  opacity: 1;
  color: var(--green);
}

.conv-item.pinned-room {
  background: linear-gradient(90deg, color-mix(in srgb, var(--green) 8%, transparent), transparent 60%);
}

.conv-item.pinned-room:hover {
  background: var(--hover);
}

.conv-item.pinned-room.selected {
  background: var(--selected);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  flex: 0 0 auto;
  overflow: hidden;
  letter-spacing: 0;
}

.avatar.group {
  border-radius: 6px;
}

.avatar-pinged {
  animation: avatar-ping 0.3s ease;
}

@keyframes avatar-ping {
  0% { transform: scale(1); box-shadow: 0 0 0 0 var(--green); }
  50% { transform: scale(0.9); box-shadow: 0 0 0 3px var(--green); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 transparent; }
}

.avatar-wrap {
  position: relative;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
}

.status-dot {
  position: absolute;
  right: -3px;
  top: -3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--sidebar);
  box-sizing: border-box;
}

.status-dot.working {
  background: #e6a23c;
}

.status-dot.done {
  background: #07c160;
}

.conv-body {
  min-width: 0;
  max-width: 100%;
  display: grid;
  gap: 3px;
  overflow: hidden;
}

.conv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.conv-title {
  flex: 1 1 auto;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.conv-time {
  font-size: 11px;
  color: var(--muted);
  flex: 0 0 auto;
}

.conv-preview {
  min-width: 0;
  max-width: 100%;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-foot {
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- chat panel ---------- */

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  /* Constrain the implicit column so a long nowrap reply preview can't expand
     the grid track past the viewport and push the send button off-screen. */
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  max-width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--chat-bg);
  position: relative; /* positioning context for the new-message pill */
}

.new-msg-pill {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  /* sit just above the composer (grid row 3) */
  bottom: 84px;
  z-index: 30;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}

.new-msg-pill.hidden {
  display: none;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  background: var(--chat-bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  flex: 0 0 auto;
}

.chat-head-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.chat-head .avatar {
  width: 34px;
  height: 34px;
  font-size: 13px;
}

.chat-head-text {
  min-width: 0;
}

.chat-head-text h2 {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-head-text p {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-head-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.chat-head-actions button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted-strong);
}

.chat-head-actions button:hover:not(:disabled) {
  background: var(--hover);
  color: var(--text);
}

/* ---------- messages ---------- */

.messages {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 100%;
}

.msg-own {
  flex-direction: row-reverse;
}

.msg-system {
  justify-content: center;
}

.msg .avatar {
  width: 38px;
  height: 38px;
  font-size: 14px;
}

.msg-content {
  min-width: 0;
  max-width: min(72%, 720px);
  display: grid;
  gap: 4px;
}

.msg-own .msg-content {
  align-items: flex-end;
}

.msg-name {
  font-size: 12px;
  color: var(--muted-strong);
  padding: 0 2px;
}

.bubble {
  position: relative;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--bubble-other);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.55;
  font-size: 14px;
  width: fit-content;
  max-width: 100%;
}

.msg-own .bubble {
  background: var(--bubble-own);
  border-color: #86d95f;
}

.msg-pending {
  opacity: 0.6;
}

.bubble.attach-pending {
  font-size: 13px;
  opacity: 0.85;
}

.msg-agent .bubble {
  font-size: 14px;
}

.bubble.markdown > :first-child {
  margin-top: 0;
}

.bubble.markdown > :last-child {
  margin-bottom: 0;
}

.bubble.markdown p {
  margin: 0 0 8px;
}

.bubble.markdown h1,
.bubble.markdown h2,
.bubble.markdown h3,
.bubble.markdown h4,
.bubble.markdown h5,
.bubble.markdown h6 {
  margin: 12px 0 6px;
  line-height: 1.3;
  font-weight: 600;
}

.bubble.markdown h1 { font-size: 18px; }
.bubble.markdown h2 { font-size: 16px; }
.bubble.markdown h3 { font-size: 15px; }
.bubble.markdown h4,
.bubble.markdown h5,
.bubble.markdown h6 { font-size: 14px; }

.bubble.markdown ul,
.bubble.markdown ol {
  margin: 4px 0 8px;
  padding-left: 22px;
}

.bubble.markdown li {
  margin: 2px 0;
}

.bubble.markdown a {
  color: var(--blue);
  text-decoration: underline;
}

.bubble.markdown strong {
  font-weight: 600;
}

.bubble.markdown code.inline {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.06);
}

.bubble .mention {
  display: inline-block;
  padding: 0 5px;
  border-radius: 4px;
  font-weight: 600;
  color: var(--green-strong);
  background: color-mix(in srgb, var(--green) 16%, transparent);
}
.msg-own .bubble .mention {
  color: #06502b;
  background: rgba(0, 0, 0, 0.12);
}

.bubble.markdown blockquote {
  margin: 6px 0;
  padding: 2px 10px;
  border-left: 3px solid var(--line);
  color: var(--muted-strong);
}

.bubble.markdown pre.code-block {
  margin: 6px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #1e1e1e;
  overflow-x: auto;
}

.bubble.markdown pre.code-block code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  line-height: 1.5;
  color: #e6e6e6;
  white-space: pre;
}

.msg-time {
  font-size: 11px;
  color: var(--muted);
  padding: 0 2px;
}

.msg-foot {
  display: flex;
  align-items: center;
  gap: 8px;
}

.msg-own .msg-foot {
  justify-content: flex-end;
}

.msg-reply-btn {
  font-size: 11px;
  color: var(--muted);
  background: transparent;
  border: none;
  padding: 0 2px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}

.msg:hover .msg-reply-btn {
  opacity: 1;
}

.msg-reply-btn:hover {
  color: var(--green-strong);
}

.quote-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  text-align: left;
  max-width: 100%;
  padding: 6px 10px;
  margin-bottom: 4px;
  border: none;
  border-left: 3px solid var(--green);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
  cursor: pointer;
}

.quote-chip .q-who {
  font-size: 12px;
  font-weight: 600;
  color: var(--green-strong);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quote-chip .q-text {
  font-size: 12px;
  color: var(--muted-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.flash .bubble {
  animation: msg-flash 1.2s ease;
}

@keyframes msg-flash {
  0%, 100% { background: var(--bubble-other); }
  30% { background: rgba(7, 193, 96, 0.22); }
}

.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-left: 3px solid var(--green);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.reply-bar.hidden {
  display: none;
}

.reply-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.reply-info .r-who {
  font-size: 12px;
  font-weight: 600;
  color: var(--green-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.reply-info .r-text {
  font-size: 12px;
  color: var(--muted-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-close {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--muted-strong);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
}

.reply-close:hover {
  color: var(--text);
}

.bubble.streaming {
  border-color: var(--green);
}

.bubble.typing {
  display: flex;
  gap: 4px;
  align-items: center;
  min-height: 20px;
}

.bubble.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted-strong);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.bubble.typing span:nth-child(2) {
  animation-delay: 0.18s;
}

.bubble.typing span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.msg-progress {
  font-size: 12px;
  color: var(--muted-strong);
  padding: 2px 2px 0;
  font-style: italic;
}

.system-pill {
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--muted-strong);
  font-size: 12px;
  max-width: 80%;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- composer ---------- */

.composer {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  padding: 12px 18px;
  background: var(--chat-bg);
  border-top: 1px solid var(--line);
}

.mention-list {
  position: absolute;
  left: 18px;
  bottom: calc(100% + 4px);
  min-width: 220px;
  max-width: 340px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 40;
}

.mention-list.hidden {
  display: none;
}

.mention-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.mention-item.active,
.mention-item:hover {
  background: var(--hover);
}

.mention-item .m-name {
  font-weight: 600;
  color: var(--text);
}

.mention-item .m-meta {
  font-size: 12px;
  color: var(--muted-strong);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
  max-width: 100%;
}

.composer-attach {
  flex: 0 0 auto;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted-strong);
}

.composer-attach:hover {
  background: var(--hover);
  color: var(--text);
}

.attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attach-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  padding: 4px 6px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.attach-chip img {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex: 0 0 auto;
}

.attach-ext {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--line-soft);
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 600;
  flex: 0 0 auto;
}

.attach-name {
  min-width: 0;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attach-remove {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  min-height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--hover);
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1;
}

.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.msg-own .msg-attachments {
  justify-content: flex-end;
}

.msg-attach-image img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: block;
}

.msg-attach-file {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 240px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
}

.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  min-height: 40px;
  max-height: 160px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  resize: none;
  line-height: 1.5;
}

.composer textarea:focus {
  border-color: var(--green);
}

.composer .primary {
  flex: 0 0 auto;
  min-width: 84px;
  min-height: 40px;
}

/* ---------- shared form ---------- */

label {
  display: grid;
  gap: 6px;
}

.field-label,
label span:first-child,
.toggle span:last-child {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 500;
}

.field-hint {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  outline: none;
}

input,
select {
  min-height: 38px;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
  padding: 10px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.primary:hover {
  background: var(--green-strong);
}

.danger {
  border-color: var(--red);
  color: var(--red);
  background: #fff;
}

.danger:hover {
  background: #fdeceb;
}

/* ---------- toggle ---------- */

.toggle {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar);
}

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #cfd6df;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  transition: transform 140ms ease;
}

.toggle input:checked + .switch {
  background: var(--green);
}

.toggle input:checked + .switch::after {
  transform: translateX(18px);
}

/* ---------- members ---------- */

.member-block {
  display: grid;
  gap: 6px;
}

.member-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.member-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar);
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
}

.check-line span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.check-line input {
  width: 16px;
  min-height: auto;
}

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.4);
}

.modal-card {
  display: grid;
  gap: 12px;
  width: min(460px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  font-size: 17px;
  font-weight: 600;
}

.icon-only {
  width: 32px;
  min-height: 32px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted-strong);
}

.icon-only:hover {
  background: var(--hover);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.modal-actions .primary {
  flex: 1;
}

/* ---------- auth ---------- */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(237, 237, 237, 0.96);
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(360px, 100%);
  padding: 26px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.12);
  text-align: center;
}

.auth-card .mark {
  justify-self: center;
  width: 46px;
  height: 46px;
}

.auth-card h1 {
  font-size: 20px;
  font-weight: 600;
}

.auth-card label {
  text-align: left;
}

.auth-card p {
  min-height: 16px;
  color: var(--red);
  font-size: 13px;
}

/* ---------- tasks ---------- */

.sidebar {
  grid-column: 1;
  grid-row: 1;
}

.chat-panel,
.tasks-panel {
  grid-column: 2;
  grid-row: 1;
}

.tasks-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  max-width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--chat-bg);
}

body:not(.view-tasks) .tasks-panel {
  display: none;
}

body.view-tasks .chat-panel {
  display: none;
}

.conv-item.pinned {
  border-bottom: 1px solid var(--line-soft);
}

.tasks-avatar {
  background: var(--green) !important;
}

.tasks-avatar svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-head .tasks-avatar svg {
  width: 18px;
  height: 18px;
}

.tasks-body {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px 18px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.task-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-group-head {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-strong);
  padding: 0 2px;
}

.task-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
}

.task-card:hover {
  border-color: var(--green);
}

.task-card.done {
  opacity: 0.6;
}

.task-check {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: #fff;
  color: transparent;
  margin-top: 1px;
}

.task-check svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

.task-check.checked {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.task-card-body {
  min-width: 0;
  flex: 1 1 auto;
  display: grid;
  gap: 6px;
}

.task-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.task-text {
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.task-card.done .task-text {
  text-decoration: line-through;
  color: var(--muted-strong);
}

.pri-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.pri-dot.pri-high {
  background: var(--red);
}

.pri-dot.pri-normal {
  background: var(--blue);
}

.pri-dot.pri-low {
  background: #c2c8d0;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.task-due {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--line-soft);
  color: var(--muted-strong);
}

.task-due.overdue {
  background: #fdeceb;
  color: var(--red);
}

.task-pri-tag {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fdeceb;
  color: var(--red);
}

.task-notes-preview {
  min-width: 0;
  flex: 1 1 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  /* single-pane: list OR chat fills the screen */
  .app-shell {
    width: 100vw;
    grid-template-columns: 1fr;
    grid-template-rows: var(--app-height, 100dvh);
    overflow-x: hidden;
  }

  .sidebar,
  .chat-panel,
  .tasks-panel {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    max-width: 100vw;
    min-height: 0;
    height: var(--app-height, 100dvh);
    overflow-x: hidden;
  }

  .sidebar {
    border-right: 0;
  }

  /* default: show list, hide panels */
  .chat-panel,
  .tasks-panel {
    display: none;
  }

  body.show-chat .sidebar {
    display: none;
  }

  body.show-chat:not(.view-tasks) .chat-panel {
    display: grid;
  }

  body.show-chat.view-tasks .tasks-panel {
    display: grid;
  }

  .back-btn {
    display: inline-flex;
  }

  .conv-item {
    padding: 12px 14px;
  }

  .pin-btn {
    opacity: 0.55;
    width: 34px;
    height: 34px;
  }

  /* No hover on touch — keep the 引用/回复 buttons visible and tappable. */
  .msg-reply-btn {
    opacity: 1;
    padding: 2px 6px;
  }

  .pin-btn svg {
    width: 18px;
    height: 18px;
  }

  .chat-head {
    padding: 12px 14px;
  }

  .messages {
    padding: 14px;
  }

  .msg-content {
    max-width: 80%;
  }

  .composer {
    padding: 10px 12px;
    /* keep above iOS home indicator */
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .composer .primary span {
    display: none;
  }

  .composer .primary {
    min-width: 48px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .modal {
    align-items: flex-end;
    padding: 0;
    padding-bottom: var(--kb-inset, 0px);
  }

  .modal-card {
    width: 100%;
    max-height: calc(92dvh - var(--kb-inset, 0px));
    border-radius: 16px 16px 0 0;
  }
}
