:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel-2: #1c2129;
  --border: #2a303a;
  --text: #e6e9ef;
  --muted: #8b94a3;
  --accent: #4f9cf9;
  --ok: #35c46b;
  --warn: #e5a33a;
  --err: #e05252;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei UI", system-ui, sans-serif;
  font-size: 14px;
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-text h1 { font-size: 15px; margin: 0; font-weight: 600; line-height: 1.2; }
.brand-text .sub { color: var(--muted); font-size: 11.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }

.top-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 12.5px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.env-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12.5px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
  padding: 14px;
  height: calc(100% - 56px);
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .side { max-height: 360px; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow: auto;
}

.chat { display: flex; flex-direction: column; gap: 12px; min-height: 0; }

.ask-box { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font: inherit;
  line-height: 1.6;
}
.ask-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.ask-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hint { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.attach-preview { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.attach-preview:empty { display: none; }
.attach-item {
  position: relative;
  width: 72px; height: 72px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #10141a;
}
.attach-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-item button {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; padding: 0;
  line-height: 1; font-size: 12px;
  border-radius: 50%;
  background: rgba(0,0,0,.7); border: none; color: #fff;
}
.attach-item .name {
  position: absolute; bottom: 0; left: 0; right: 0;
  font-size: 9px; padding: 1px 3px;
  background: rgba(0,0,0,.6); color: #ccc;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ask-box.dragover { border-color: var(--accent); background: #17202b; }

button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06101f; font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--err); border-color: #4a2a2a; }
button.icon { padding: 5px 9px; }
button.small-btn { font-size: 12px; padding: 5px 10px; }

.hidden { display: none !important; }

.task-view { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; }
.task-head { display: flex; align-items: center; justify-content: space-between; }
.task-meta { display: flex; align-items: center; gap: 10px; }
.muted { color: var(--muted); font-size: 12px; }
.small { font-size: 12px; }

.badge { padding: 3px 9px; border-radius: 999px; font-size: 12px; background: #243042; color: #a9c6f0; }
.badge.running { background: #2b2f1d; color: var(--warn); }
.badge.done { background: #173323; color: var(--ok); }
.badge.error { background: #3a1d1d; color: var(--err); }
.badge.cancelled { background: #2a2a2a; color: var(--muted); }

.progress { height: 3px; background: #20242c; border-radius: 2px; overflow: hidden; }
.progress .bar { height: 100%; width: 30%; background: var(--accent); animation: slide 1.4s infinite ease-in-out; }
.progress.idle .bar { animation: none; width: 100%; background: var(--ok); }
.progress.err .bar { animation: none; width: 100%; background: var(--err); }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }

.cols { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 14px; flex: 1; min-height: 0; }
@media (max-width: 820px) { .cols { grid-template-columns: 1fr; } }

.trace-col, .answer-col { min-height: 0; overflow: auto; }
.trace-col h3 { font-size: 12.5px; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.trace { margin: 0; padding-left: 16px; display: flex; flex-direction: column; gap: 7px; }
.trace li { color: #c2c9d6; font-size: 12.5px; line-height: 1.5; }
.trace li .t { color: var(--muted); font-size: 11px; margin-right: 6px; }
.trace li.fail { color: #f0a3a3; }

.markdown { line-height: 1.72; }
.markdown.empty { color: var(--muted); }
.markdown h2 { font-size: 16px; margin: 18px 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.markdown h3 { font-size: 14px; margin: 14px 0 6px; }
.markdown p { margin: 7px 0; }
.markdown ul, .markdown ol { margin: 7px 0; padding-left: 22px; }
.markdown li { margin: 3px 0; }
.markdown code { background: #232a35; padding: 1px 5px; border-radius: 4px; font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
.markdown pre { background: #10141a; border: 1px solid var(--border); border-radius: 8px; padding: 11px; overflow: auto; }
.markdown pre code { background: transparent; padding: 0; }
.markdown blockquote { border-left: 3px solid var(--border); margin: 7px 0; padding-left: 11px; color: var(--muted); }
.markdown table { border-collapse: collapse; width: 100%; margin: 9px 0; display: block; overflow-x: auto; table-layout: auto; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; font-size: 12.5px; white-space: nowrap; }
.markdown th { background: var(--panel-2); position: sticky; top: 0; }
.markdown a { color: var(--accent); }
.markdown.streaming .caret { display: inline-block; width: 7px; height: 14px; background: var(--accent); margin-left: 2px; vertical-align: text-bottom; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.err-text { color: var(--err); }

.side h2 { font-size: 12.5px; color: var(--muted); margin: 0 0 9px; font-weight: 600; }
.history { display: flex; flex-direction: column; gap: 5px; }
.history-item { padding: 8px 10px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; background: var(--panel-2); }
.history-item:hover { border-color: var(--border); }
.history-item .q { font-size: 12.5px; line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.history-item .m { color: var(--muted); font-size: 11px; margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.st-done { color: var(--ok); }
.st-error { color: var(--err); }
.st-running { color: var(--warn); }

.dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 20px; width: min(420px, 92vw); }
.dialog.wide { width: min(560px, 94vw); }
.dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog h2 { margin: 0 0 12px; font-size: 16px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; }
.dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); margin: 10px 0; }
.dialog input { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 8px 10px; font: inherit; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.sources { display: flex; flex-direction: column; }
.source { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.source .on { color: var(--ok); }
.source .off { color: var(--muted); }
.source em { display: block; font-style: normal; font-size: 11px; color: var(--err); margin-top: 2px; }
.cache-info { margin-top: 14px; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.cache-row code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.cache-row.err { color: var(--err); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2a313d; border: 1px solid var(--border); padding: 9px 15px; border-radius: 8px; font-size: 13px; z-index: 10; }
.toast.err { border-color: #5a2a2a; color: #f0a3a3; }
