:root {
  color-scheme: dark;
  --bg: #07030d;
  --panel: rgba(12, 7, 18, 0.94);
  --panel-2: #1c0d2c;
  --line: rgba(196, 43, 255, 0.22);
  --text: #f7f2f8;
  --muted: #b9a6c6;
  --amber: #ff3d8a;
  --amber-ink: #fff8fc;
  --amber-dim: rgba(196, 43, 255, 0.24);
  --green: #5ef0c3;
  --red: #ff6b8a;
  --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:
    radial-gradient(900px 420px at 8% -10%, rgba(196, 43, 255, 0.28), transparent 58%),
    radial-gradient(720px 380px at 100% 0%, rgba(255, 46, 136, 0.18), transparent 52%),
    var(--bg);
}
body::before {
  content: "";
  position: fixed;
  inset: -48px;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(196, 43, 255, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(196, 43, 255, 0.09) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 20%, #000 10%, transparent 72%);
  animation: grid-drift 22s linear infinite;
}
.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: minmax(200px, 250px) minmax(0, 1fr) minmax(300px, 400px);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "top top top"
    "side editor chat";
}

.app > header {
  grid-area: top;
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(196, 43, 255, 0.2);
  background: rgba(10, 4, 16, 0.94);
  backdrop-filter: blur(14px);
}
.app > header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, #ff2e88, #c42bff, #ff7a3d, transparent);
  background-repeat: no-repeat;
  background-size: 28% 100%;
  animation: sweep 5.5s linear infinite;
}
.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: 36px;
  height: 36px;
  border-radius: 9px;
  display: block;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(255, 46, 136, 0.35), 0 0 16px rgba(196, 43, 255, 0.28);
}
.workspace-label {
  flex: 1;
  min-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #9a88a8;
  font-family: var(--mono);
  font-size: 11px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(196, 43, 255, 0.16);
  border-radius: 999px;
  padding: 5px 10px;
}
.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; }
#modelSwitch, #fieldModelPick {
  height: 30px;
  background: rgba(7, 3, 13, 0.65);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  max-width: 220px;
}

.sidebar, .editor, .chat {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}
.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}
.editor {
  grid-area: editor;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255, 46, 136, 0.06), transparent 90px),
    #09060f;
}
.chat {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
}

.side-head, .editor-bar, .chat-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 6px 12px;
  border-bottom: 1px solid rgba(196, 43, 255, 0.16);
  background: rgba(255, 255, 255, 0.015);
}
.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(196, 43, 255, 0.1); }
.tree-item.active {
  background: rgba(255, 46, 136, 0.12);
  color: #fff;
  box-shadow: inset 2px 0 0 #ff2e88;
}

.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: 12px 14px 24px;
  background: transparent;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 20px;
  tab-size: 2;
  outline: none;
  caret-color: #ff8ac4;
}
.editor-empty {
  flex: 1;
  padding: 28px 22px;
  color: var(--muted);
  line-height: 1.6;
}

.chat-log { flex: 1; overflow: auto; padding: 14px; }
#welcome { color: var(--muted); line-height: 1.6; padding: 8px 4px 16px; }
.welcome-logo {
  width: 112px;
  height: 112px;
  border-radius: 16px;
  display: block;
  margin: 4px 0 14px;
  box-shadow: 0 0 0 1px rgba(255, 46, 136, 0.32), 0 10px 28px rgba(196, 43, 255, 0.22);
}
.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: linear-gradient(135deg, rgba(255, 46, 136, 0.16), rgba(196, 43, 255, 0.12));
  border: 1px solid rgba(255, 46, 136, 0.28);
  border-radius: 10px;
  padding: 10px 12px;
}
.msg.assistant .body { line-height: 1.65; }
.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 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: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 2px; }
.chips button {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(196, 43, 255, 0.2);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.4;
}
.chips button:hover { color: var(--text); border-color: rgba(255, 46, 136, 0.55); background: rgba(255, 46, 136, 0.08); }
.composer { padding: 10px 12px 12px; border-top: 1px solid rgba(196, 43, 255, 0.12); }
#chatInput {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  max-height: 180px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  outline: none;
}
#chatInput:focus, #fileSearch:focus, dialog input:focus, .admin-card input:focus {
  border-color: #ff2e88;
  box-shadow: 0 0 0 3px rgba(196, 43, 255, 0.22);
}
.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: linear-gradient(100deg, #ff2e88, #c42bff 70%);
  color: #fff;
  border: 0;
  font-weight: 650;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset, 0 6px 16px rgba(255, 46, 136, 0.22);
}
.primary:disabled { background: #2a1830; color: #8d7a96; opacity: 1; box-shadow: none; }
.ghost { background: rgba(255, 255, 255, 0.02); border: 1px solid rgba(196, 43, 255, 0.24); color: inherit; }
a.ghost { text-decoration: none; }
.admin-page { min-height: 100vh; }
.admin-wrap { max-width: 880px; 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 { width: 100%; margin-top: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
@media (max-width: 720px) { .admin-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(196, 43, 255, 0.14); border-color: rgba(255, 46, 136, 0.55); }

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 .app > header::after { animation-duration: 1.4s; }
body.streaming .chat-head > span::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 8px;
  border-radius: 50%;
  background: #5ef0c3;
  box-shadow: 0 0 10px #5ef0c3;
  animation: blink 0.8s ease-in-out infinite;
}

@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 {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(180px, 30vh) minmax(200px, 1fr) minmax(240px, 46vh);
    grid-template-areas:
      "top"
      "side"
      "editor"
      "chat";
  }
  .sidebar, .chat { border: 0; border-top: 1px solid var(--line); }
  .search-hits { max-height: 96px; }
}
