:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "Microsoft YaHei UI", sans-serif;
  color: #191c1f;
  background: #f5f6f3;
  font-synthesis: none;
  --line: #dfe2dc;
  --muted: #68706b;
  --green: #16764c;
  --green-strong: #0c5d3a;
  --ink: #191c1f;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  background: #fff;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: #f5f6f3;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 40px;
}

.brand-mark,
.empty-mark,
.dialog-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid #aeb5af;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-weight: 700;
}

.brand strong,
.brand span {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  font-size: 14px;
}

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid #c9cec8;
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  font-weight: 600;
}

.new-chat:hover {
  border-color: #9ea69f;
  background: #fafbf9;
}

.conversation-section {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.section-label {
  padding: 0 4px 7px;
  color: var(--muted);
  font-size: 12px;
}

.conversation-list,
.conversation-dialog-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
  min-width: 0;
  overflow-y: auto;
}

.conversation-list {
  flex: 1 1 auto;
  min-height: 0;
  align-content: start;
}

.conversation-item {
  display: grid;
  gap: 4px;
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #303632;
  background: transparent;
  text-align: left;
}

.conversation-item:hover {
  background: #e9ece8;
}

.conversation-item.active {
  border-color: #cfd8d1;
  background: #e3ebe6;
}

.conversation-item strong,
.conversation-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item strong {
  font-size: 12px;
  font-weight: 600;
}

.conversation-item span {
  color: var(--muted);
  font-size: 10px;
}

.conversation-item .conversation-workspace {
  color: #296246;
  font-size: 10px;
  font-weight: 600;
}

.conversation-group-label {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 7px 5px;
  color: #777f79;
  background: #f5f6f3;
  font-size: 10px;
  font-weight: 700;
}

.conversation-search {
  width: calc(100% - 8px);
  min-height: 34px;
  margin: 2px 4px 5px;
  padding: 7px 9px;
  border: 1px solid #d5dad5;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font-size: 12px;
  letter-spacing: 0;
}

.conversation-search:focus {
  border-color: #7d9b89;
  outline: 2px solid #dce9e1;
}

.conversation-list-note {
  padding: 10px;
  color: var(--muted);
  font-size: 11px;
}

.conversation-item:disabled {
  cursor: default;
  opacity: 0.62;
}

.session-meta {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 0 4px;
}

.session-meta span {
  color: var(--muted);
  font-size: 12px;
}

.session-meta strong {
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b5bab6;
}

.status-dot.online {
  background: #1b8b5a;
  box-shadow: 0 0 0 3px #d8eee3;
}

.status-dot.busy {
  background: #c47a14;
  box-shadow: 0 0 0 3px #fae9cb;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  background: #fff;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-width: 0;
  min-height: 70px;
  padding: 14px 28px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.topbar p {
  margin: 0;
  letter-spacing: 0;
}

.topbar > div:first-child {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
}

.topbar h1 {
  overflow: hidden;
  font-size: 17px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.messages {
  overflow-x: hidden;
  overflow-y: auto;
  padding: 30px max(24px, calc((100% - 800px) / 2));
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 100%;
  color: var(--muted);
}

.empty-state h2 {
  margin: 14px 0 0;
  color: #3a403c;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
}

.empty-mark {
  width: 44px;
  height: 44px;
}

.message {
  display: grid;
  gap: 7px;
  min-width: 0;
  margin: 0 0 26px;
}

.message.user {
  justify-items: end;
}

.message-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.message-body {
  min-width: 0;
  max-width: min(100%, 720px);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.68;
  letter-spacing: 0;
}

.message.user .message-body {
  max-width: min(82%, 620px);
  padding: 11px 14px;
  border-radius: 7px 7px 2px 7px;
  color: #17241d;
  background: #e8f2ec;
}

.message.assistant .message-body {
  width: 100%;
  color: #262b28;
}

.message-quote {
  width: min(100%, 620px);
  margin: 0;
  padding: 9px 12px;
  overflow: hidden;
  border-left: 3px solid #7d9487;
  border-radius: 0 5px 5px 0;
  color: #4e5751;
  background: #f1f3f0;
}

.message.user .message-quote {
  max-width: min(82%, 620px);
}

.message-quote span {
  display: block;
  margin-bottom: 3px;
  color: #16764c;
  font-size: 10px;
  font-weight: 700;
}

.message-quote p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
}

.markdown-body {
  white-space: normal;
}

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

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

.markdown-body p {
  margin: 0 0 14px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 24px 0 10px;
  color: #171b18;
  line-height: 1.35;
  letter-spacing: 0;
}

.markdown-body h1 {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 23px;
}

.markdown-body h2 {
  padding-bottom: 6px;
  border-bottom: 1px solid #e8eae7;
  font-size: 19px;
}

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

.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  font-size: 15px;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0 0 14px;
  padding-left: 24px;
}

.markdown-body li {
  padding-left: 2px;
}

.markdown-body li + li {
  margin-top: 5px;
}

.markdown-body li > p {
  margin-bottom: 7px;
}

.markdown-body blockquote {
  margin: 0 0 14px;
  padding: 9px 14px;
  border-left: 3px solid #9aa99f;
  color: #505853;
  background: #f6f8f6;
}

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

.markdown-body hr {
  height: 1px;
  margin: 24px 0;
  border: 0;
  background: var(--line);
}

.markdown-body a {
  color: #0c6842;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.markdown-body a:hover {
  color: #084c31;
}

.markdown-body code {
  font-family: "Cascadia Code", Consolas, "SFMono-Regular", monospace;
  font-size: 0.9em;
}

.markdown-body :not(pre) > code {
  padding: 2px 5px;
  border: 1px solid #e0e4df;
  border-radius: 4px;
  color: #315342;
  background: #f3f5f2;
  overflow-wrap: anywhere;
}

.markdown-body pre {
  position: relative;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin: 0 0 16px;
  padding: 38px 15px 15px;
  overflow-x: auto;
  border: 1px solid #dfe3df;
  border-radius: 6px;
  color: #252b27;
  background: #f5f7f5;
  line-height: 1.55;
  tab-size: 2;
}

.markdown-body pre code {
  display: block;
  min-width: max-content;
  white-space: pre;
}

.code-tools {
  position: absolute;
  top: 7px;
  right: 7px;
  display: flex;
  gap: 6px;
}

.copy-code,
.fit-code {
  min-width: 54px;
  min-height: 26px;
  padding: 3px 8px;
  border: 1px solid #d5dad5;
  border-radius: 5px;
  color: #58605b;
  background: #fff;
  font-size: 11px;
}

.copy-code:hover,
.fit-code:hover {
  color: #242925;
  background: #ecefeb;
}

.diagram-code.fit-width {
  overflow-x: hidden;
}

.diagram-code.fit-width code {
  max-width: 100%;
}

.table-scroll {
  max-width: 100%;
  margin: 0 0 16px;
  overflow-x: auto;
  border: 1px solid #dfe3df;
  border-radius: 6px;
}

.markdown-body table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13px;
}

.markdown-body th,
.markdown-body td {
  padding: 9px 11px;
  border-right: 1px solid #e1e4e0;
  border-bottom: 1px solid #e1e4e0;
  text-align: left;
  vertical-align: top;
}

.markdown-body th:last-child,
.markdown-body td:last-child {
  border-right: 0;
}

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

.markdown-body th {
  color: #333a35;
  background: #f3f5f2;
  font-weight: 600;
}

.markdown-body img {
  display: block;
  max-width: 100%;
  max-height: min(70dvh, 720px);
  height: auto;
  margin: 0 0 14px;
  border-radius: 6px;
  object-fit: contain;
}

.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-width: min(100%, 720px);
}

.file-badge {
  display: grid;
  min-width: 140px;
  max-width: min(100%, 320px);
  padding: 9px 11px;
  border: 1px solid #d8ddd8;
  border-radius: 6px;
  color: #303632;
  background: #f7f8f6;
}

.file-badge strong {
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-badge span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.message.system .message-body {
  padding: 10px 12px;
  border-left: 3px solid #c47a14;
  color: #6d4813;
  background: #fff8ec;
  font-size: 13px;
}

.activity {
  display: flex;
  align-items: center;
  gap: 9px;
  width: min(800px, calc(100% - 48px));
  min-height: 32px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.activity[hidden] {
  display: none;
}

.activity-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid #ced4cf;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.composer {
  display: grid;
  gap: 8px;
  width: min(800px, calc(100% - 48px));
  margin: 8px auto max(18px, env(safe-area-inset-bottom));
  padding: 7px;
  border: 1px solid #cfd4ce;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 28px rgb(27 37 31 / 8%);
}

.composer:focus-within {
  border-color: #7d9487;
  box-shadow: 0 0 0 3px rgb(22 118 76 / 9%), 0 8px 28px rgb(27 37 31 / 8%);
}

.composer.dragging {
  border-color: var(--green);
  background: #f5faf7;
}

.composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 66px 42px;
  gap: 8px;
  align-items: end;
}

.pending-files {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 2px;
}

.pending-quote {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 8px;
  align-items: center;
  padding: 8px 8px 8px 11px;
  border-left: 3px solid var(--green);
  border-radius: 0 6px 6px 0;
  background: #f2f5f1;
}

.pending-quote[hidden] {
  display: none;
}

.pending-quote > div {
  min-width: 0;
}

.pending-quote span {
  display: block;
  margin-bottom: 2px;
  color: var(--green);
  font-size: 10px;
  font-weight: 700;
}

.pending-quote blockquote {
  margin: 0;
  overflow: hidden;
  color: #4e5751;
  font-size: 12px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-quote button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  color: #69706b;
  background: transparent;
  font-size: 18px;
}

.pending-quote button:hover {
  color: #242925;
  background: #e2e6e1;
}

.selection-quote-button {
  position: fixed;
  z-index: 30;
  width: 64px;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: #252b27;
  box-shadow: 0 5px 16px rgb(25 31 27 / 22%);
  font-size: 12px;
  font-weight: 700;
}

.selection-quote-button[hidden] {
  display: none;
}

.pending-file {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
  max-width: min(100%, 300px);
  min-height: 42px;
  padding: 6px 6px 6px 10px;
  border: 1px solid #d8ddd8;
  border-radius: 6px;
  background: #f7f8f6;
}

.pending-file.uploading {
  border-color: #d7c08e;
  background: #fff9ed;
}

.pending-file.error {
  border-color: #e2b8b4;
  background: #fff4f3;
}

.pending-file-info {
  display: grid;
  min-width: 0;
}

.pending-file-info strong {
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pending-file-info span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.pending-file.error .pending-file-info span {
  color: #9a3b34;
}

.pending-file button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: 5px;
  color: #69706b;
  background: transparent;
  font-size: 18px;
}

.pending-file button:hover {
  color: #242925;
  background: #e7eae6;
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  padding: 9px 8px;
  overflow-y: auto;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  line-height: 1.5;
}

.composer textarea::placeholder {
  color: #8b928d;
}

.send-button,
.stop-button,
.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 7px;
  color: #fff;
  background: var(--green);
  font-size: 20px;
  font-weight: 700;
}

.attach-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 66px;
  height: 42px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  color: #444b46;
  background: #eef0ed;
  font-size: 12px;
  font-weight: 600;
}

.attach-button span {
  font-size: 17px;
  line-height: 1;
}

.attach-button:hover {
  background: #e2e6e1;
}

.attach-button:disabled {
  cursor: default;
  color: #9ba19d;
  background: #f1f2f0;
}

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

.send-button:disabled {
  cursor: default;
  color: #a1a7a3;
  background: #e5e8e4;
}

.stop-button {
  color: #7c241f;
  background: #f6dedc;
  font-size: 13px;
}

.mobile-only {
  display: none;
  color: var(--ink);
  background: #eef0ed;
}

.mobile-actions {
  flex: 0 0 92px;
  grid-template-columns: repeat(2, 42px);
  gap: 8px;
}

.mobile-actions .icon-button {
  color: var(--ink);
  background: #eef0ed;
}

.mobile-actions .icon-button:hover {
  background: #e2e6e1;
}

dialog {
  width: min(390px, calc(100% - 32px));
  padding: 0;
  border: 1px solid #d2d6d1;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 24px 70px rgb(19 27 22 / 24%);
}

dialog::backdrop {
  background: rgb(20 25 22 / 38%);
}

dialog form {
  display: grid;
  gap: 12px;
  padding: 26px;
}

.dialog-mark {
  width: 42px;
  height: 42px;
}

dialog h2 {
  margin: 5px 0 6px;
  font-size: 18px;
  letter-spacing: 0;
}

dialog label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

dialog input {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #c8cec8;
  border-radius: 6px;
  outline: 0;
}

dialog input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgb(22 118 76 / 10%);
}

dialog button {
  min-height: 42px;
  margin-top: 4px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--green);
  font-weight: 600;
}

.conversation-dialog {
  width: min(440px, calc(100% - 24px));
  min-width: 0;
  max-height: min(680px, calc(100dvh - 32px));
}

.conversation-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.conversation-dialog-header h2,
.conversation-dialog-header p {
  margin: 0;
}

.conversation-dialog-header h2 {
  font-size: 17px;
}

.conversation-dialog-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.conversation-dialog .dialog-close {
  display: grid;
  place-items: center;
  width: 38px;
  min-height: 38px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  color: #555d57;
  background: #eef0ed;
  font-size: 20px;
}

.conversation-dialog-list {
  max-height: calc(100dvh - 150px);
  padding: 10px;
}

.conversation-dialog .conversation-group-label {
  background: #fff;
}

.conversation-dialog .conversation-item {
  min-height: 54px;
  margin: 0;
  color: #303632;
  background: transparent;
}

.conversation-dialog .conversation-item:hover {
  background: #f0f2ef;
}

.conversation-dialog .conversation-item.active {
  color: #173d2a;
  background: #e3ebe6;
}

.form-error {
  margin: -4px 0 0;
  color: #a33931;
  font-size: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 700px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .chat-panel {
    height: 100dvh;
  }

  .topbar {
    min-height: 62px;
    padding: 10px 16px;
  }

  .mobile-only {
    display: grid;
  }

  .messages {
    padding: 22px 16px;
  }

  .message {
    margin-bottom: 22px;
  }

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

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

  .activity,
  .composer {
    width: calc(100% - 24px);
  }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
