: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.12);
  --ink: #f5f6f2;
  --muted: #8f9894;
  --accent: #31e29b;
  --accent-soft: rgba(49, 226, 155, 0.1);
  --warn: #e6b65f;
  --error: #f06b5d;
  --shadow: 0 18px 56px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  min-height: 100vh;
}

body {
  overflow: hidden;
  color: var(--ink);
  font-family: ui-sans-serif, "PingFang SC", "Microsoft YaHei", sans-serif;
  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;
  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%);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
h1 { font-size: 34px; line-height: 1.08; }
h2 { font-size: 18px; line-height: 1.2; }

.role-shell {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(310px, 360px) minmax(0, 1fr) minmax(320px, 400px);
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

.left-rail,
.right-rail,
.center-stage {
  min-height: 0;
  min-width: 0;
}

.left-rail,
.right-rail {
  display: grid;
  align-content: start;
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.center-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  overflow: hidden;
}

.brand-panel,
.panel,
.project-topbar,
.composer,
.message-card,
.history-view,
dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.brand-panel,
.panel,
.project-topbar,
.composer {
  padding: 16px;
}

.brand-panel {
  display: grid;
  gap: 12px;
}

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

.status-pill {
  justify-self: start;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-pill.ok {
  background: var(--accent-soft);
  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;
}

.panel {
  display: grid;
  gap: 12px;
}

.panel-head,
.project-topbar,
.topbar-actions,
.composer-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-actions,
.composer-actions,
.dialog-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

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

.field span,
.panel-head small,
.muted-text {
  color: var(--muted);
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

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

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); }

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

.primary-button,
.secondary-button,
.danger-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
}

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

.secondary-button {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
}

.danger-button {
  border-color: rgba(240, 107, 93, 0.28);
  background: rgba(240, 107, 93, 0.12);
  color: #ffb1a8;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.compact {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.role-list,
.project-list,
.material-list {
  display: grid;
  gap: 9px;
  min-height: 0;
}

.project-list {
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.role-card,
.project-card,
.material-card,
.suggestion-card {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
  padding: 11px;
  text-align: left;
}

.role-card.active,
.project-card.active {
  border-color: rgba(49, 226, 155, 0.42);
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.role-card strong,
.project-card strong,
.material-card strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-card small,
.project-card small,
.material-card small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.35;
}

.project-topbar {
  min-height: 78px;
}

.project-topbar h2 {
  font-size: 24px;
}

#modelSelect {
  width: 210px;
}

.message-stream,
.history-view {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 8px 2px 2px;
  scrollbar-gutter: stable;
}

.message-stream {
  display: grid;
  align-content: start;
  gap: 12px;
}

.history-view {
  display: block;
  padding: 18px;
  white-space: pre-wrap;
  line-height: 1.7;
}

.hidden { display: none !important; }

.message-card {
  padding: 16px;
  box-shadow: none;
}

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

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

.message-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.message-meta strong {
  color: var(--ink);
}

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

.composer {
  position: relative;
  display: grid;
  gap: 10px;
  box-shadow: none;
}

.mention-picker {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(100% - 10px);
  z-index: 10;
  display: grid;
  gap: 6px;
  max-height: 270px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 19, 22, 0.98);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
}

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

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

.mention-item:hover,
.mention-item.active {
  border-color: rgba(49, 226, 155, 0.28);
  background: var(--accent-soft);
}

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

.selected-chip {
  max-width: 100%;
  border: 1px solid rgba(49, 226, 155, 0.26);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 7px 10px;
  font-size: 13px;
}

.upload-zone {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 112px;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  text-align: center;
  padding: 16px;
}

.upload-zone input { display: none; }
.upload-zone strong { color: var(--accent); }
.upload-zone.drag-active {
  border-color: rgba(49, 226, 155, 0.45);
  background: var(--accent-soft);
}

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

.material-list {
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.material-card {
  display: grid;
  gap: 8px;
}

.material-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
}

.material-preview img,
.material-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.material-type {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-weight: 800;
}

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

.memory-block:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.memory-block ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.55;
}

.suggestion-list {
  display: grid;
  gap: 8px;
}

.suggestion-card {
  display: grid;
  gap: 8px;
}

.suggestion-card textarea {
  min-height: 72px;
}

dialog {
  width: min(720px, calc(100vw - 28px));
  color: var(--ink);
  padding: 0;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

dialog form {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.memory-dialog {
  width: min(840px, calc(100vw - 28px));
}

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

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

  .left-rail,
  .right-rail {
    overflow: visible;
  }

  .center-stage {
    min-height: 760px;
  }

  .project-list,
  .material-list {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .project-topbar,
  .panel-head,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  #modelSelect {
    width: 100%;
  }

  .url-import,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}
