:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-soft: #f1f4f9;
  --text: #172033;
  --muted: #6d7b91;
  --line: #dfe5ee;
  --brand: #2563eb;
  --danger: #b42318;
  --shadow: 0 18px 46px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

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

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

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  font-weight: 900;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
}

.nav-button,
.primary-link,
.secondary-link,
.primary-action,
.secondary-action,
.danger-action {
  display: inline-grid;
  min-height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  cursor: pointer;
  font-weight: 900;
}

.nav-button,
.secondary-action,
.secondary-link {
  background: #fff;
}

.primary-action,
.primary-link {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}

.danger-action {
  color: var(--danger);
  border-color: #fecaca;
  background: #fff7f7;
}

.project-list {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.project-row {
  display: grid;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  background: transparent;
  text-align: left;
}

.project-row:hover,
.project-row.is-active {
  border-color: var(--line);
  background: #fff;
}

.project-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.workspace-main {
  min-width: 0;
  padding: 24px;
}

.workspace-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.workspace-topbar h1 {
  margin: 0;
  font-size: 26px;
}

.workspace-topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 16px;
}

.panel {
  display: grid;
  gap: 14px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.wide-panel {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.compact-search {
  width: min(220px, 34vw);
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.field input,
.field textarea,
.file-move-select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
}

.field textarea {
  resize: vertical;
}

.file-list,
.thread-list,
.artifact-list,
.image-gallery {
  display: grid;
  gap: 8px;
}

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

.file-main,
.thread-main {
  min-width: 0;
}

.file-preview-button {
  border: 0;
  padding: 0;
  color: inherit;
  cursor: pointer;
  background: transparent;
  text-align: left;
}

.file-preview-button:hover strong {
  color: var(--brand);
}

.file-main strong,
.thread-main strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-main span,
.thread-main span,
.empty-state {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.file-move-select {
  width: 180px;
  height: 36px;
  padding: 0 8px;
}

.file-actions {
  display: grid;
  grid-template-columns: auto auto 180px;
  gap: 8px;
  align-items: center;
}

.preview-panel {
  min-height: 220px;
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: #fbfcfe;
}

.preview-title {
  margin-bottom: 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.preview-panel pre {
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.artifact-item {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.artifact-item img,
.artifact-file-icon {
  width: 84px;
  height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  background: #f8fafc;
}

.artifact-file-icon {
  display: grid;
  place-items: center;
  color: var(--brand);
  font-weight: 900;
}

.artifact-main {
  min-width: 0;
}

.artifact-main strong,
.image-card strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.artifact-main span,
.image-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.mini-actions a {
  display: inline-grid;
  min-height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--text);
  background: #fff;
  font-size: 12px;
  font-weight: 900;
}

.image-gallery {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.image-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.image-card img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 7px;
  object-fit: cover;
  background: #f8fafc;
}

.gallery-page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.gallery-image-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  box-shadow: var(--shadow);
}

.gallery-image-card img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  object-fit: cover;
  background: #f8fafc;
}

.gallery-image-main {
  min-width: 0;
}

.gallery-image-main strong {
  display: -webkit-box;
  min-height: 42px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.45;
}

.gallery-image-main span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.gallery-empty {
  grid-column: 1 / -1;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 999px;
  color: #fff;
  background: #111827;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 820px) {
  .workspace-shell,
  .workspace-grid {
    grid-template-columns: 1fr;
  }

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

  .workspace-main {
    padding: 16px;
  }

  .workspace-topbar,
  .file-item,
  .thread-item,
  .artifact-item {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .panel-actions,
  .file-actions {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .compact-search,
  .file-move-select {
    width: 100%;
  }

  .artifact-item img,
  .artifact-file-icon {
    width: 100%;
    height: 120px;
  }

  .gallery-page-grid {
    grid-template-columns: 1fr;
  }
}
