:root {
  --bg: #f4f3ef;
  --card: rgba(255, 255, 255, 0.78);
  --card-strong: #ffffff;
  --text: #171717;
  --muted: #6b6b6b;
  --line: rgba(17, 24, 39, 0.08);
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.06);
  --radius-xl: 24px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --ok: #1f7a4f;
  --warn: #9b6a00;
  --danger: #b42318;
  --brand: #161f2d;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.86), transparent 34%),
    linear-gradient(180deg, #f7f6f2 0%, #f0efea 100%);
  min-height: 100vh;
}
button, textarea, input { font: inherit; }
button { border: 0; background: transparent; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.65; }

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px 16px;
  backdrop-filter: blur(10px);
  background: rgba(250, 249, 245, 0.72);
  overflow: auto;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.sidebar-header h2 {
  margin: 0;
  font-size: 22px;
}
.sidebar-eyebrow {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.thread-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.thread-item {
  width: 100%;
  cursor: pointer;
  text-align: left;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.74);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.thread-item:focus-visible {
  outline: 2px solid rgba(22,31,45,0.28);
  outline-offset: 2px;
}
.thread-item.active {
  border-color: rgba(22,31,45,0.18);
  background: #fff;
}
.thread-item-main { min-width: 0; }
.thread-item-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-item-preview {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
  min-height: 2.9em;
}
.thread-item-time {
  font-size: 12px;
  color: var(--muted);
}
.thread-delete-btn {
  align-self: start;
  color: var(--danger);
  border: 1px solid rgba(180,35,24,0.12);
  background: rgba(255,255,255,0.7);
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 13px;
}
.empty-state {
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--line);
  color: var(--muted);
  background: rgba(255,255,255,0.42);
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 18px 20px 20px;
  gap: 14px;
}
.topbar {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}
.thread-title {
  margin: 0;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn,
.ghost-btn,
.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  min-width: 48px;
  min-height: 48px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.74);
  color: var(--brand);
  box-shadow: var(--shadow);
}
.ghost-btn { padding: 0 16px; font-weight: 600; }

.banner-host {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.banner {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.72);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  line-height: 1.6;
}
.banner.warn { color: var(--warn); }
.banner.error { color: var(--danger); }
.banner.success { color: var(--ok); }

.message-list {
  flex: 1;
  min-height: 280px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 4px;
}
.message-card {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.avatar {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 800;
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--line);
}
.message-main {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255,255,255,0.8);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.message-meta {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 10px;
}
.meta-divider { opacity: 0.6; }
.message-content {
  font-size: 16px;
  line-height: 1.8;
  word-break: break-word;
}
.message-content p { margin: 0 0 12px; }
.message-content p:last-child { margin-bottom: 0; }
.message-notices {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.notice-item {
  font-size: 13px;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(244,243,239,0.9);
  border: 1px dashed var(--line);
}

.composer-shell {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.composer-files {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.file-chip {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(255,255,255,0.84);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.file-chip-main { min-width: 0; }
.file-chip-name {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}
.file-chip-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.file-chip-remove {
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.75);
}
.composer-box {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255,255,255,0.84);
  box-shadow: var(--shadow);
  padding: 14px 16px 12px;
}
#messageInput {
  width: 100%;
  min-height: 72px;
  max-height: 220px;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  outline: none;
  padding: 6px 4px 10px;
  font-size: 16px;
  line-height: 1.7;
}
#messageInput::placeholder { color: #8b8b8b; }
.composer-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.composer-hint {
  color: var(--muted);
  font-size: 13px;
}
.composer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.toolbox {
  position: relative;
}
.tool-btn {
  font-size: 26px;
  line-height: 1;
}
.tool-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  min-width: 180px;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.95);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tool-menu-item {
  text-align: left;
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(244,243,239,0.8);
}
.send-btn {
  min-width: 94px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 360px);
    z-index: 20;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    background: rgba(248,247,243,0.96);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.18);
    z-index: 10;
  }
  .workspace { padding: 16px; }
}

@media (max-width: 640px) {
  .workspace { gap: 12px; }
  .thread-title { font-size: 24px; }
  .message-card { grid-template-columns: 44px minmax(0, 1fr); gap: 10px; }
  .avatar { width: 44px; height: 44px; border-radius: 14px; }
  .message-main { padding: 15px 16px; border-radius: 20px; }
  .composer-box { padding: 12px 12px 10px; border-radius: 22px; }
  .composer-footer { align-items: stretch; flex-direction: column; }
  .composer-actions { justify-content: flex-end; }
  .file-chip-name { max-width: 180px; }
}
