:root {
  color-scheme: dark;
  --bg: #0e1014;
  --panel: #16181e;
  --panel-2: #1c1f27;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f4f6;
  --muted: #9aa1ab;
  --amber: #ff4d88;
  --amber-ink: #fff8fc;
  --amber-dim: rgba(255, 77, 136, 0.18);
  --green: #3dd68c;
  --red: #ff6b81;
  --mono: "Cascadia Code", "Cascadia Mono", Consolas, "Sarasa Gothic SC", monospace;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  background: var(--bg);
}
.app, .admin-wrap { position: relative; z-index: 1; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
input, textarea, select { outline: none; }
::placeholder { color: #7d6c8a; }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: 56px minmax(0, 1fr);
  grid-template-areas:
    "top top"
    "side main";
}
.app:has(#editor:not([hidden])) {
  grid-template-columns: 232px minmax(380px, 1fr) minmax(360px, 42vw);
  grid-template-areas:
    "top top top"
    "side main editor";
}

.app > header {
  grid-area: top;
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: #0e1014;
}
.head-gap { flex: 1; min-width: 8px; }
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand strong {
  display: block;
  color: var(--text);
  font-size: 15px;
  letter-spacing: 0.04em;
  line-height: 1.2;
}
.brand small { display: block; color: var(--muted); font-size: 11px; line-height: 1.3; margin-top: 1px; }
.mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: block;
  object-fit: cover;
}
.workspace-label { display: none; }
.shell-flag {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
  font-size: 12px;
}
.shell-flag.on { color: var(--green); border-color: #3d5a36; }
#expertSwitch, #modelSwitch, #fieldModelPick {
  height: 32px;
  background: #171a21;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  max-width: 180px;
}

.sidebar, .editor, .chat {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}
.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  background: #101218;
  border-right: 1px solid var(--line);
}
.editor {
  grid-area: editor;
  display: none;
  flex-direction: column;
  background: #101218;
  border-left: 1px solid var(--line);
}
.app:has(#editor:not([hidden])) .editor,
.app:has(#office:not([hidden])) .editor { display: flex; }
#office { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#office[hidden] { display: none !important; }
#officeFrame { width: 100%; height: 42%; border: 0; background: #0e1014; }
#officeFrame[hidden] { display: none !important; }
.office-hint { margin: 8px 12px 0; color: var(--muted); font-size: 12px; }
#officeText {
  flex: 1;
  min-height: 0;
  margin: 8px;
  border: 0;
  background: transparent;
  resize: none;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
}
.plan {
  margin: 12px auto 0;
  width: min(760px, calc(100% - 48px));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #171a21;
  padding: 10px 12px;
}
.plan ol { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.plan li { color: var(--muted); }
.plan li.doing { color: var(--text); }
.plan li.done { color: var(--green); }
.plan li.blocked { color: var(--red); }
.confirm-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: #241820;
  border: 1px solid rgba(255, 77, 136, 0.35);
}
.confirm-bar div { flex: 1; min-width: 0; }
.confirm-bar strong { display: block; }
.confirm-bar p { margin: 2px 0 0; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.composer { position: relative; }
.mention {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(100% - 8px);
  max-height: 220px;
  overflow: auto;
  background: #1c1f27;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  z-index: 3;
}
.mention button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text);
}
.mention button.active, .mention button:hover { background: #2a2418; }
.release { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.release-copy {
  width: 100%;
  min-height: 52px;
  resize: vertical;
  background: #12141a;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}
.release-row { display: flex; flex-wrap: wrap; gap: 6px; }
.release-note { margin: 0; color: var(--muted); font-size: 12px; }
.shots { display: flex; gap: 8px; margin-bottom: 8px; }
.shots img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; }
.chat {
  grid-area: main;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.task-list {
  max-height: 220px;
  overflow: auto;
  padding: 4px 8px 8px;
  border-bottom: 1px solid var(--line);
}
.task-row { display: flex; align-items: center; gap: 2px; }
.task-open {
  flex: 1;
  min-width: 0;
  height: 30px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 0 8px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-row.active .task-open { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.task-open:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.task-del {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0;
}
.task-del:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.side-head, .editor-bar, .chat-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: transparent;
}
.chat-head { flex-wrap: wrap; }
.side-head > span, .chat-head > span { margin-right: auto; font-size: 13px; letter-spacing: 0.04em; }
.editor-bar span:first-child, .side-head span, .chat-head span {
  font-weight: 650;
}
#editorPath {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
}
#editorMeta { color: var(--muted); font-size: 12px; flex: none; }

#fileSearch {
  margin: 8px 10px 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
}
.tree { flex: 1; overflow: auto; padding: 6px; }
.tree ul { list-style: none; margin: 0; padding: 0 0 0 12px; }
.tree > ul { padding-left: 0; }
.tree-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 28px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 0 8px;
  color: #efe8f2;
  font-size: 13px;
}
.tree-item:not(.dir) { padding-left: 22px; }
.tree-item.dir { font-weight: 650; }
.tree-item.dir::before {
  content: "▸";
  width: 14px;
  color: var(--muted);
  font-size: 10px;
}
li.open > .tree-item.dir::before { content: "▾"; }
.tree-item:hover { background: rgba(255, 255, 255, 0.05); }
.tree-item.active {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  box-shadow: inset 2px 0 0 var(--amber);
}

.search-hits {
  max-height: 180px;
  overflow: auto;
  margin: 8px 10px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.search-hits button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  font-family: var(--mono);
  font-size: 12px;
}
.search-hits button:hover { background: rgba(196, 43, 255, 0.12); }
.search-hits .hit-path { color: var(--amber); }
.search-hits .hit-text { color: var(--muted); }

#editor {
  flex: 1;
  width: 100%;
  resize: none;
  border: 0;
  margin: 0;
  padding: 16px 18px 24px;
  background: transparent;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 22px;
  tab-size: 2;
  outline: none;
  caret-color: #ff8ab4;
}
.editor-empty {
  flex: 1;
  padding: 28px 22px;
  color: var(--muted);
  line-height: 1.6;
}

.chat-log {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  padding: 28px 32px 8px;
}
#welcome {
  width: min(680px, 100%);
  margin: auto;
  color: var(--muted);
  line-height: 1.6;
  padding: 0 0 12px;
}
.gate-cs { margin-top: 0; }
.gate-cs a { color: #ff8ab4; text-decoration: none; }
.gate-cs a:hover { text-decoration: underline; }
.welcome-line {
  margin: 16px 0 0;
  color: var(--text);
  font-size: 30px;
  font-weight: 650;
  letter-spacing: 0;
}
.welcome-sub { margin: 8px 0 20px; font-size: 15px; }
.welcome-logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: block;
  box-shadow: none;
}
#messages { width: min(760px, 100%); margin: 0 auto; }
.check-list, .note-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 12px; }
.check-list label { display: flex; gap: 8px; align-items: flex-start; }
.check-list small, .note-list button { color: var(--muted); }
.note-list button {
  text-align: left;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}
.design-shot { display: block; max-width: 100%; max-height: 180px; border-radius: 8px; margin-top: 8px; }
#designName { flex: none; }
.msg { margin: 0 0 12px; }
.msg.user .body {
  white-space: pre-wrap;
  background: #1c2030;
  border: 0;
  border-radius: 16px;
  padding: 12px 14px;
  margin-left: 16%;
}
.msg.assistant .body { line-height: 1.7; font-size: 15px; }
.msg.assistant .body p { margin: 0 0 8px; }
.msg .body code, .md code {
  font-family: var(--mono);
  font-size: 12.5px;
}
.msg .body code {
  background: rgba(196, 43, 255, 0.16);
  border-radius: 4px;
  padding: 0 4px;
}
.md {
  overflow: auto;
  background: #07040e;
  border: 1px solid rgba(196, 43, 255, 0.2);
  border-radius: 8px;
  padding: 10px;
  line-height: 1.45;
}
.reasoning {
  color: var(--muted);
  font-size: 12px;
  white-space: pre-wrap;
  border-left: 2px solid var(--line);
  padding: 4px 0 8px 8px;
  margin-bottom: 8px;
  max-height: 140px;
  overflow: auto;
}
.reasoning::before {
  content: "思考";
  display: block;
  color: var(--amber);
  font-weight: 650;
  margin-bottom: 4px;
}
.tool {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  margin: 0 0 8px;
  background: rgba(8, 4, 14, 0.72);
}
.tool.bad { border-color: rgba(255, 107, 138, 0.7); }
.tool-title { display: flex; gap: 8px; align-items: baseline; }
.tool-title strong { font-size: 13px; }
.tool-title em {
  color: var(--muted);
  font-style: normal;
  font-family: var(--mono);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-file {
  display: inline-block;
  margin-top: 8px;
  color: var(--text);
}
.tool-media {
  display: block;
  width: min(100%, 520px);
  margin-top: 8px;
  border-radius: 8px;
  background: #000;
}
.tool summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.tool pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 12px;
  margin: 6px 0 0;
}
.err { color: var(--red); margin: 6px 0; }

.chips { display: grid; gap: 8px; padding: 0; }
.chips button {
  text-align: left;
  background: #171a21;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.4;
}
.chips button:hover { border-color: rgba(255, 255, 255, 0.18); background: #1d212b; }
.composer {
  width: min(760px, calc(100% - 48px));
  margin: 8px auto 18px;
  padding: 12px 12px 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #171a21;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}
#chatInput {
  width: 100%;
  resize: none;
  min-height: 52px;
  max-height: 180px;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 4px 6px 0;
  font-size: 15px;
  outline: none;
}
.composer:focus-within { border-color: rgba(255, 255, 255, 0.2); }
#fileSearch:focus, dialog input:focus, .admin-card input:focus {
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow: none;
}
.composer-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
.composer-row .hint { flex: 1; }

.primary, .ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  border-radius: 8px;
  padding: 0 12px;
  line-height: 1;
}
.primary {
  background: #ff4d88;
  color: #fff;
  border: 0;
  font-weight: 650;
}
.primary:disabled { background: #2a2e38; color: #8b919c; opacity: 1; box-shadow: none; }
.ghost { background: transparent; border: 1px solid var(--line); color: inherit; }
a.ghost, a.primary { text-decoration: none; color: inherit; }
a.primary { color: #fff; }
.admin-page { min-height: 100vh; }
.admin-wrap { max-width: 960px; margin: 0 auto; padding: 28px 16px 48px; }
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(196, 43, 255, 0.18);
  background: none;
}
.admin-head .brand { text-decoration: none; color: inherit; }
#loginForm { max-width: 420px; margin: 36px auto 0; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.admin-card {
  background: rgba(14, 7, 22, 0.92);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 16px 8px;
  margin-bottom: 16px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}
.admin-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 15px;
}
.admin-card h2::before {
  content: "";
  width: 3px;
  height: 14px;
  border-radius: 99px;
  background: linear-gradient(#ff2e88, #c42bff);
}
.admin-grid .admin-card { margin-bottom: 0; }
.admin-card + .admin-grid { margin-top: 16px; }
.admin-card ul { list-style: none; margin: 0; padding: 0; }
.admin-card li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-height: 36px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(196, 43, 255, 0.12);
}
.admin-card li:last-child { border-bottom: 0; }
.admin-card li span { margin-right: auto; min-width: 0; }
.admin-card li small { flex: 1 0 100%; color: var(--muted); line-height: 1.45; }
.admin-card label { display: block; margin: 8px 0; }
.admin-card input, .admin-card select { width: 100%; margin-top: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; color: inherit; }
.admin-tabs { display: flex; gap: 8px; margin: 0 0 16px; flex-wrap: wrap; }
.admin-tabs button[aria-selected="true"] { border-color: #ff2e88; color: #fff; box-shadow: 0 0 16px rgba(255, 46, 136, 0.2); }
.admin-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.admin-stat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.admin-stat b { display: block; margin-top: 4px; font-size: 22px; }
.cost-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
#planList form + form { margin-top: 16px; padding-top: 12px; border-top: 1px solid rgba(196, 43, 255, 0.12); }
#planList .primary, .cost-grid > .panel-actions { grid-column: 1 / -1; justify-self: start; width: auto; }
.member-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.member-actions select { width: auto; margin: 0; }
@media (max-width: 720px) {
  .admin-grid, .admin-stats, .cost-grid { grid-template-columns: 1fr; }
}
.tiny { height: 26px; padding: 0 8px; font-size: 12px; }
.primary:hover:not(:disabled) { filter: brightness(1.05); }
.ghost:hover { background: rgba(255, 255, 255, 0.05); border-color: rgba(255, 255, 255, 0.16); }

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
}
dialog::backdrop { background: rgba(7, 3, 13, 0.72); backdrop-filter: blur(4px); }
.panel {
  width: min(520px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 46, 136, 0.2);
}
.panel-head, .panel-actions { display: flex; align-items: center; gap: 8px; }
.panel-head { justify-content: space-between; margin-bottom: 8px; }
.panel-actions { justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.panel label { display: block; margin-top: 10px; font-size: 13px; color: var(--muted); }
.panel input[type="url"], .panel input[type="text"], .panel input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}
.key-row { display: flex; gap: 6px; align-items: center; }
.key-row input { flex: 1; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
.check input { width: auto; }
.panel .hint { margin: 10px 0 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: rgba(18, 8, 28, 0.94);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  max-width: min(640px, calc(100vw - 24px));
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #4a245f; border-radius: 99px; }

body.streaming #sendBtn { opacity: 0.7; }

@keyframes grid-drift {
  from { transform: translateY(0); }
  to { transform: translateY(46px); }
}
@keyframes sweep {
  from { background-position: -30% 0; }
  to { background-position: 130% 0; }
}
@keyframes blink {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}

@media (max-width: 880px) {
  .app, .app:has(#editor:not([hidden])) {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) minmax(140px, 26vh);
    grid-template-areas:
      "top"
      "main"
      "side";
  }
  .app:has(#editor:not([hidden])) {
    grid-template-areas:
      "top"
      "main"
      "editor";
  }
  .composer { width: calc(100% - 24px); }
  .chat-log { padding: 20px 16px 8px; }
  .welcome-line { font-size: 24px; }
  .search-hits { max-height: 96px; }
}
