:root {
  color-scheme: light;
  --bg: #f3f6f2;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: #ffffff;
  --line: #d8e1d7;
  --ink: #17211b;
  --muted: #617167;
  --accent: #176d4d;
  --accent-strong: #0c4d39;
  --warn: #b35f00;
  --error: #a1271d;
}

* { box-sizing: border-box; }

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 18%, rgba(23, 109, 77, 0.12), transparent 22rem),
    radial-gradient(circle at 84% 10%, rgba(216, 155, 43, 0.14), transparent 20rem),
    linear-gradient(135deg, #f8fbf7 0%, #eef4ef 48%, #f7faf9 100%);
  color: var(--ink);
  font-family: ui-sans-serif, "PingFang SC", "Microsoft YaHei", sans-serif;
}

button, input, textarea, select { font: inherit; }

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

.chat-sidebar {
  display: grid;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: rgba(255,255,255,0.38);
  backdrop-filter: blur(18px);
}

.chat-main {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 20px;
  gap: 16px;
}

.chat-header,
.config-card,
.upload-card,
.history-card,
.composer,
.message-card,
.preview-card {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 50px rgba(23, 33, 27, 0.06);
}

.chat-header,
.config-card,
.upload-card,
.history-card,
.composer {
  padding: 16px;
}

.chat-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }
h1 { font-size: 30px; line-height: 1.1; }
h2 { font-size: 18px; line-height: 1.2; }

.status-pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: #eef4ef;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.ok { background: #def1e8; }
.status-pill.warn { background: #fff0d8; color: var(--warn); }
.status-pill.bad { background: #ffe3df; color: var(--error); }

.config-card,
.upload-card,
.history-card {
  display: grid;
  gap: 12px;
}

.config-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--accent-strong);
  cursor: pointer;
}

.icon-button:hover,
.icon-button.active {
  border-color: rgba(23, 109, 77, 0.42);
  background: #eef7f1;
}

.advanced-config {
  display: grid;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.advanced-config.hidden {
  display: none;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 13px;
  color: var(--muted);
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--ink);
  padding: 12px 14px;
  border-radius: 10px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

input:focus, textarea:focus, select:focus {
  border-color: rgba(23, 109, 77, 0.5);
  box-shadow: 0 0 0 4px rgba(23, 109, 77, 0.08);
}

.primary-button,
.secondary-button {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 16px;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.secondary-button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.upload-zone {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 116px;
  border: 1px dashed #b7c7ba;
  border-radius: 14px;
  background: #fbfdfb;
  color: var(--muted);
  text-align: center;
  padding: 16px;
  cursor: pointer;
}

.upload-zone input { display: none; }
.upload-zone strong { color: var(--accent-strong); }
.upload-zone.drag-active {
  border-color: var(--accent);
  background: #eef7f1;
  color: var(--accent-strong);
}

.upload-zone.is-busy {
  opacity: 0.68;
  cursor: wait;
}

.upload-zone::after {
  content: attr(data-progress);
  font-size: 12px;
  color: var(--muted);
  min-height: 1em;
}

.url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.message-stream {
  display: grid;
  gap: 12px;
  min-height: 0;
}

.conversation-list {
  display: grid;
  gap: 10px;
  max-height: 330px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 6px 2px 2px;
  scrollbar-gutter: stable;
}

.file-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: 10px;
  height: 430px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 6px 2px 2px;
  scrollbar-gutter: stable;
}

.file-list.empty::before,
.conversation-list:empty::before {
  content: "暂无内容";
  color: var(--muted);
  padding: 12px 2px;
}

.file-list.empty {
  display: block;
}

.file-item,
.conversation-item,
.message-card,
.preview-card {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.88);
  border-radius: 14px;
}

.file-item { padding: 8px; }
.conversation-item {
  position: relative;
  min-height: 98px;
  padding: 12px 42px 12px 12px;
}

.conversation-item.active {
  border-color: rgba(23, 109, 77, 0.55);
  background: rgba(232, 244, 238, 0.94);
  box-shadow: inset 3px 0 0 var(--accent);
}

.file-meta,
.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.file-actions,
.message-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.file-item {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 6px;
  min-width: 0;
  position: relative;
}

.file-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
  padding-right: 22px;
}

.file-tile-head strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 11px;
  line-height: 1.25;
  white-space: nowrap;
}

.file-warning {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #fff0d8;
  color: var(--warn);
  font-size: 11px;
  font-weight: 700;
}

.file-tile-preview {
  width: 100%;
  aspect-ratio: 1 / 1;
}

.file-tile-thumb,
.file-type-tile {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
}

.file-type-tile {
  display: grid;
  place-items: center;
  background: #eef4ef;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 700;
}

.file-item small {
  min-width: max-content;
  overflow: visible;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
  white-space: nowrap;
}

.file-delete-button {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(216, 225, 215, 0.92);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.file-delete-button:hover {
  border-color: rgba(161, 39, 29, 0.28);
  background: #ffe3df;
  color: var(--error);
}

.conversation-delete-button {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(216, 225, 215, 0.92);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.conversation-delete-button:hover {
  border-color: rgba(161, 39, 29, 0.28);
  background: #ffe3df;
  color: var(--error);
}

.message-stream {
  align-content: start;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 8px 2px 2px;
  scrollbar-gutter: stable;
}

.message-card {
  padding: 16px;
}

.message-card.user {
  background: #f8fbf7;
}

.message-card.assistant {
  background: #ffffff;
}

.message-body {
  white-space: pre-wrap;
  line-height: 1.65;
  margin-top: 10px;
}

.composer {
  display: grid;
  gap: 12px;
  position: relative;
}

.mention-picker {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(100% - 10px);
  z-index: 10;
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 46px rgba(23, 33, 27, 0.16);
}

.mention-picker.hidden,
.selected-files-bar.hidden {
  display: none;
}

.mention-item {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.mention-item small {
  color: var(--muted);
}

.mention-item:hover,
.mention-item.active {
  border-color: rgba(23, 109, 77, 0.28);
  background: #eef7f1;
}

.selected-files-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.selected-file-chip {
  max-width: 100%;
  padding: 7px 10px;
  border: 1px solid rgba(23, 109, 77, 0.26);
  border-radius: 999px;
  background: #eef7f1;
  color: var(--accent-strong);
  font-size: 13px;
  cursor: pointer;
}

.composer-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.error-note {
  color: var(--error);
  font-size: 13px;
}

.hint-note {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 980px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .chat-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .chat-main {
    min-height: 760px;
  }
}

/* Portal visual theme alignment. Preserve chat layout and bindings. */
:root {
  color-scheme: dark;
  --bg: #090b0d;
  --panel: rgba(17, 19, 22, 0.78);
  --panel-strong: rgba(20, 23, 27, 0.96);
  --line: rgba(255, 255, 255, 0.115);
  --ink: #f5f6f2;
  --muted: #8f9894;
  --accent: #31e29b;
  --accent-strong: #31e29b;
  --warn: #e6b65f;
  --error: #f06b5d;
  --shadow: 0 18px 56px rgba(0, 0, 0, 0.34);
}

body {
  position: relative;
  color: var(--ink);
  background:
    linear-gradient(115deg, rgba(49, 226, 155, 0.09), transparent 34%),
    linear-gradient(250deg, rgba(114, 167, 255, 0.1), transparent 42%),
    #090b0d;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  content: "";
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.032) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.032) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, #000 0%, rgba(0, 0, 0, 0.82) 62%, transparent 100%);
}

.app-shell {
  position: relative;
  z-index: 1;
}

.chat-sidebar,
.chat-main,
.chat-header,
.config-card,
.upload-card,
.history-card,
.composer,
.message-card,
.preview-card,
.file-item,
.conversation-item,
.mention-picker,
.selected-file-chip {
  border-color: var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.chat-sidebar,
.chat-main {
  background: transparent;
}

.chat-header,
.config-card,
.upload-card,
.history-card,
.composer,
.message-card,
.preview-card {
  box-shadow: none;
}

.chat-header,
.config-card,
.upload-card,
.history-card,
.composer,
.message-card,
.preview-card,
.file-item,
.conversation-item {
  border-radius: 8px;
}

.status-pill,
.icon-button,
.primary-button,
.secondary-button,
.upload-zone,
input,
textarea,
select {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
}

.status-pill.ok {
  background: rgba(49, 226, 155, 0.08);
  color: var(--accent);
}

.status-pill.warn {
  background: rgba(230, 182, 95, 0.1);
  color: #ffd89a;
}

.status-pill.bad {
  background: rgba(240, 107, 93, 0.1);
  color: #ffb1a8;
}

.icon-button:hover,
.icon-button.active,
.secondary-button:hover,
.upload-zone.drag-active,
.mention-item:hover,
.mention-item.active,
.selected-file-chip {
  border-color: rgba(49, 226, 155, 0.28);
  background: rgba(49, 226, 155, 0.08);
  color: var(--accent);
}

.primary-button {
  border: 1px solid rgba(49, 226, 155, 0.32);
  background: var(--accent);
  color: #04110c;
}

.chat-sidebar {
  border-right: 1px solid var(--line);
}

.chat-header,
.config-card,
.upload-card,
.history-card,
.composer,
.message-card,
.preview-card {
  border: 1px solid var(--line);
}

.file-list,
.conversation-list,
.message-stream {
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.file-item,
.conversation-item,
.message-card,
.preview-card {
  background: rgba(17, 19, 22, 0.72);
}

.conversation-item.active {
  border-color: rgba(49, 226, 155, 0.4);
  background: rgba(49, 226, 155, 0.08);
  box-shadow: inset 3px 0 0 var(--accent);
}

.file-delete-button,
.conversation-delete-button {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(17, 19, 22, 0.88);
  color: var(--muted);
}

.file-delete-button:hover,
.conversation-delete-button:hover {
  border-color: rgba(240, 107, 93, 0.26);
  background: rgba(240, 107, 93, 0.12);
  color: var(--error);
}

.file-type-tile,
.message-card.user {
  background: rgba(255, 255, 255, 0.04);
}

.message-card.assistant {
  background: rgba(17, 19, 22, 0.78);
}

.mention-picker {
  border: 1px solid var(--line);
  background: rgba(17, 19, 22, 0.98);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
}

.mention-item img {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.file-warning {
  background: rgba(230, 182, 95, 0.1);
  color: #ffd89a;
}

.error-note {
  color: #ffb1a8;
}

.hint-note,
.file-item small,
.upload-note,
.config-card small,
.history-card small,
.mention-item small,
.message-meta small {
  color: var(--muted);
}

.file-item strong,
.conversation-item strong,
.message-meta strong,
.upload-head span,
.field span {
  color: var(--ink);
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(49, 226, 155, 0.5);
  box-shadow: 0 0 0 3px rgba(49, 226, 155, 0.14);
}

::placeholder {
  color: rgba(198, 206, 201, 0.58);
}
