:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --surface: #fffefd;
  --surface-2: #f2f5f1;
  --surface-3: #eef4f7;
  --line: #dde3dc;
  --line-strong: #c8d1c8;
  --text: #1f2724;
  --muted: #6c7772;
  --muted-2: #8a9590;
  --accent: #23746f;
  --accent-strong: #185a56;
  --accent-soft: #e2f1ee;
  --warn: #b54a42;
  --user: #dff0ec;
  --assistant: #fffefd;
  --code-bg: #f1f4f2;
  --shadow-soft: 0 20px 50px rgba(36, 47, 42, 0.08);
  --shadow-pop: 0 10px 28px rgba(35, 116, 111, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: 100dvh;
  min-height: 0;
  background: var(--surface);
}

.sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #f8f9f6;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 14px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: #243833;
  font-weight: 800;
}

.brand-title,
.chat-title,
.footer-title {
  font-weight: 760;
}

.brand-title {
  letter-spacing: 0;
}

.brand-subtitle,
.chat-subtitle,
.footer-subtitle,
.composer-hint {
  color: var(--muted);
  font-size: 13px;
}

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  margin: 4px 16px 14px;
  border: 1px solid rgba(35, 116, 111, 0.18);
  border-radius: 10px;
  color: #fff;
  background: var(--accent);
  font-weight: 720;
  box-shadow: var(--shadow-pop);
}

.new-chat:hover {
  background: var(--accent-strong);
}

.conversation-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  padding: 0 10px 12px;
}

.conversation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  border-radius: 10px;
}

.conversation-row:hover,
.conversation-row.active {
  background: #edf3ef;
}

.conversation-row.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.conversation-item {
  width: 100%;
  min-height: 40px;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  padding: 0 12px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-delete {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: var(--muted-2);
  background: transparent;
  font-size: 19px;
  line-height: 1;
  opacity: 0;
}

.conversation-row:hover .conversation-delete,
.conversation-row.active .conversation-delete {
  opacity: 1;
}

.conversation-delete:hover {
  color: var(--warn);
  background: rgba(181, 74, 66, 0.1);
}

.sidebar-tools {
  padding: 0 14px 10px;
}

.sidebar-tool-button {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
}

.sidebar-tool-button:hover {
  color: var(--warn);
  border-color: rgba(181, 74, 66, 0.28);
  background: rgba(181, 74, 66, 0.06);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 14px 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #c28b35;
}

.status-dot.ready {
  background: var(--accent);
}

.status-dot.error {
  background: var(--warn);
}

.chat-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto 1fr auto;
  background: var(--surface);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 253, 0.92);
}

.topbar > div {
  min-width: 0;
}

.chat-title {
  overflow: hidden;
  max-width: 62vw;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ghost-button,
.icon-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  background: var(--surface);
  padding: 0 13px;
}

.ghost-button:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.icon-button {
  width: 38px;
  padding: 0;
}

.mobile-menu {
  display: none;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 28px clamp(28px, 5vw, 72px);
  background:
    linear-gradient(180deg, #fbfbf8 0%, #fffefd 38%, #fffefd 100%);
  scroll-behavior: smooth;
}

.welcome {
  display: grid;
  min-height: 100%;
  align-content: center;
  justify-items: center;
  text-align: center;
}

.welcome.hidden {
  display: none;
}

.welcome-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 16px;
  color: #fff;
  background: #243833;
  font-weight: 820;
}

.welcome h1 {
  margin: 18px 0 8px;
  font-size: clamp(30px, 4.2vw, 52px);
  letter-spacing: 0;
}

.welcome p {
  margin: 0 0 24px;
  color: var(--muted);
}

.prompt-grid {
  display: grid;
  width: min(900px, 100%);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.prompt-grid button {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface);
  padding: 0 16px;
  text-align: left;
  box-shadow: 0 8px 24px rgba(31, 39, 36, 0.04);
}

.prompt-grid button:hover {
  border-color: rgba(35, 116, 111, 0.28);
  background: var(--accent-soft);
}

.message {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 13px;
  width: min(1120px, 100%);
  margin: 0 auto 22px;
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 38px;
  justify-content: end;
}

.avatar {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: #52635d;
  font-size: 13px;
  font-weight: 800;
}

.message.user .avatar {
  grid-column: 2;
  background: var(--accent);
}

.bubble {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--assistant);
  padding: 14px 16px;
  line-height: 1.72;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 28px rgba(31, 39, 36, 0.045);
}

.message.assistant .bubble {
  width: 100%;
}

.message.user .bubble {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  width: fit-content;
  max-width: min(760px, 86%);
  border-color: rgba(35, 116, 111, 0.2);
  color: #102b29;
  background: var(--user);
  white-space: pre-wrap;
  box-shadow: none;
}

.message.loading .bubble::after {
  display: inline-block;
  width: 1.2em;
  content: "▋";
  color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}

.markdown-body {
  font-size: 15.5px;
}

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

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

.markdown-body p {
  margin: 0 0 10px;
  white-space: normal;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 17px 0 8px;
  line-height: 1.34;
  letter-spacing: 0;
}

.markdown-body h1 {
  font-size: 24px;
}

.markdown-body h2 {
  font-size: 21px;
}

.markdown-body h3 {
  font-size: 18px;
}

.markdown-body h4 {
  font-size: 16px;
}

.markdown-body ul {
  margin: 0 0 12px;
  padding-left: 22px;
}

.markdown-body li {
  margin: 4px 0;
}

.markdown-body .table-wrap {
  overflow-x: auto;
  margin: 10px 0 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.markdown-body table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.5;
}

.markdown-body th,
.markdown-body td {
  border-bottom: 1px solid #e3e9e4;
  padding: 10px 12px;
  vertical-align: top;
}

.markdown-body th {
  background: #eef4f1;
  color: var(--text);
  font-weight: 740;
}

.markdown-body tr:last-child td {
  border-bottom: 0;
}

.markdown-body .align-left {
  text-align: left;
}

.markdown-body .align-center {
  text-align: center;
}

.markdown-body .align-right {
  text-align: right;
}

.markdown-body blockquote {
  margin: 0 0 12px;
  border-left: 3px solid rgba(35, 116, 111, 0.42);
  padding: 5px 0 5px 12px;
  color: #41504b;
  background: rgba(35, 116, 111, 0.07);
  border-radius: 0 9px 9px 0;
}

.markdown-body pre {
  position: relative;
  overflow-x: auto;
  margin: 10px 0 13px;
  border: 1px solid #d8e0d8;
  border-radius: 10px;
  background: var(--code-bg);
  padding: 14px;
  color: var(--text);
  line-height: 1.58;
}

.markdown-body pre code {
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: 13px;
  white-space: pre;
}

.markdown-body code {
  border: 1px solid rgba(35, 116, 111, 0.18);
  border-radius: 6px;
  background: rgba(35, 116, 111, 0.08);
  padding: 1px 5px;
  color: #1e625e;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.markdown-body .code-label {
  margin: -4px 0 8px;
  color: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
}

.markdown-body a {
  color: var(--accent-strong);
  text-decoration: none;
  border-bottom: 1px solid rgba(35, 116, 111, 0.32);
}

.markdown-body a:hover {
  border-bottom-color: currentColor;
}

.composer {
  padding: 14px clamp(28px, 5vw, 72px) 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 254, 253, 0.96);
}

.attachment-preview {
  display: flex;
  gap: 10px;
  width: min(1120px, 100%);
  margin: 0 auto 10px;
  overflow-x: auto;
}

.attachment-item {
  position: relative;
  width: 86px;
  height: 86px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.attachment-item img,
.image-strip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-item button {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(31, 39, 36, 0.72);
  font-size: 18px;
  line-height: 1;
}

.image-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 180px));
  gap: 8px;
  margin-top: 10px;
}

.image-strip img {
  aspect-ratio: 4 / 3;
  border: 1px solid rgba(35, 116, 111, 0.2);
  border-radius: 10px;
  background: #fff;
}

.input-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  width: min(1120px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 12px 34px rgba(31, 39, 36, 0.08);
  padding: 9px;
}

textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 9px 10px;
  color: var(--text);
  line-height: 1.5;
}

textarea::placeholder {
  color: var(--muted-2);
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.send-button,
.stop-button,
.tool-button {
  border: 0;
  border-radius: 10px;
  font-weight: 800;
}

.tool-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 22px;
  line-height: 1;
}

.tool-button:hover {
  background: #d5ebe7;
}

.send-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  color: #fff;
  background: var(--accent);
  font-size: 22px;
}

.send-button:hover {
  background: var(--accent-strong);
}

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

.stop-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface-2);
}

.hidden {
  display: none !important;
}

.composer-hint {
  width: min(1120px, 100%);
  margin: 8px auto 0;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 10;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    border-right: 1px solid var(--line);
    box-shadow: 18px 0 45px rgba(31, 39, 36, 0.16);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: block;
  }

  .topbar {
    padding: 0 16px;
  }

  .messages {
    padding: 20px 16px;
  }

  .composer {
    padding: 12px 14px 14px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    height: 100dvh;
  }

  .topbar {
    min-height: 58px;
    gap: 10px;
  }

  .chat-title {
    max-width: 54vw;
    font-size: 15px;
  }

  .chat-subtitle {
    display: none;
  }

  .ghost-button {
    min-height: 34px;
    padding: 0 11px;
  }

  .messages {
    padding: 16px 12px;
    background: var(--surface);
  }

  .welcome {
    align-content: start;
    padding-top: 12vh;
  }

  .welcome-mark {
    width: 48px;
    height: 48px;
    border-radius: 13px;
  }

  .welcome h1 {
    margin-top: 14px;
    font-size: 30px;
  }

  .welcome p {
    max-width: 280px;
    margin-bottom: 18px;
    line-height: 1.55;
  }

  .prompt-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .prompt-grid button {
    min-height: 46px;
    border-radius: 9px;
    padding: 0 13px;
    font-size: 14px;
  }

  .message,
  .message.user {
    gap: 8px;
    width: 100%;
    margin-bottom: 16px;
  }

  .message {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .message.user {
    grid-template-columns: minmax(0, 1fr) 30px;
  }

  .avatar {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    font-size: 12px;
  }

  .bubble {
    border-radius: 12px;
    padding: 11px 12px;
    line-height: 1.68;
    box-shadow: none;
  }

  .message.user .bubble {
    max-width: 90%;
  }

  .markdown-body {
    font-size: 15px;
  }

  .markdown-body h1 {
    font-size: 21px;
  }

  .markdown-body h2 {
    font-size: 19px;
  }

  .markdown-body .table-wrap {
    margin-right: -4px;
    margin-left: -4px;
  }

  .composer {
    padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  }

  .input-wrap {
    border-radius: 13px;
    padding: 7px;
  }

  textarea {
    max-height: 140px;
    padding: 8px;
  }

  .composer-actions {
    gap: 6px;
  }

  .tool-button,
  .send-button {
    width: 36px;
    height: 36px;
    border-radius: 9px;
  }

  .stop-button {
    min-height: 34px;
    padding: 0 10px;
  }

  .composer-hint {
    display: none;
  }
}
