:root {
  --bg: #0b1020; --card: #141b2e; --border: #2a3654;
  --text: #e8eef9; --muted: #94a3b8; --accent: #38bdf8; --accent2: #a78bfa;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, #1a2744, var(--bg));
  color: var(--text); line-height: 1.6;
}
.wrap { max-width: 640px; margin: 0 auto; padding: 32px 20px 48px; }
.wrap.wide { max-width: 900px; }
h1 { font-size: 1.6rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; margin: 16px 0;
}
label { display: block; margin: 12px 0; font-size: 0.9rem; color: var(--muted); }
input, textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  border-radius: 8px; border: 1px solid var(--border);
  background: #0f1528; color: var(--text); font: inherit;
}
button {
  margin-top: 12px; padding: 10px 18px; border: 0; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #0b1020; font-weight: 600; cursor: pointer;
}
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.row label { flex: 1; min-width: 140px; }
.berserk { display: flex; align-items: center; gap: 8px; color: #f87171; }
.task .meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.status { min-height: 1.5em; }
.err { color: #f87171; }
a { color: var(--accent); }

/* Agent chat */
body.chat-page { overflow: hidden; height: 100dvh; }
.chat-shell {
  display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto;
  background: var(--bg);
}
.chat-header {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--card);
}
.chat-header h1 { font-size: 1rem; margin: 0; }
.chat-header-main { flex: 1; min-width: 140px; }
.author-pick { font-size: 0.75rem; color: var(--muted); }
.author-pick input {
  width: 120px; margin-top: 4px; padding: 6px 8px; font-size: 0.85rem;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
  background: #0f1528; color: var(--text); cursor: pointer; text-decoration: none;
}
.attach-label { cursor: pointer; font-size: 1rem; }
.chat-messages {
  flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.empty-chat { text-align: center; margin-top: 2rem; }
.msg {
  max-width: 92%; padding: 10px 14px; border-radius: 14px; font-size: 0.92rem;
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #0b1020;
}
.msg.agent, .msg.stream {
  align-self: flex-start; background: var(--card); border: 1px solid var(--border);
}
.msg.system {
  align-self: center; max-width: 100%; background: transparent;
  border: 1px dashed var(--border); color: var(--muted); font-size: 0.8rem;
}
.msg-head {
  display: flex; gap: 8px; font-size: 0.7rem; font-weight: 700; margin-bottom: 4px; opacity: 0.85;
}
.msg-text { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.msg-imgs img { max-height: 200px; border-radius: 10px; margin-top: 8px; display: block; }
.stream-steps { margin: 0; padding-left: 0; list-style: none; }
.stream-steps li { font-size: 0.8rem; padding: 2px 0; color: var(--muted); }
.working .dots span { animation: bounce 1s infinite; display: inline-block; }
.working .dots span:nth-child(2) { animation-delay: 0.12s; }
.working .dots span:nth-child(3) { animation-delay: 0.24s; }
@keyframes bounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-3px)} }
.chat-compose {
  border-top: 1px solid var(--border); padding: 10px 16px 16px; background: var(--card);
}
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.compose-row textarea {
  flex: 1; min-height: 40px; max-height: 120px; resize: none; margin: 0;
}
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; margin: 0; padding: 0; font-size: 1.2rem;
}
.attach-preview { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.attach-thumb { position: relative; }
.attach-thumb img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.attach-thumb button {
  position: absolute; top: 0; right: 0; margin: 0; padding: 0 6px; font-size: 0.7rem;
  background: #fff; color: #c00; border-radius: 50%; min-width: 0;
}
.approval-bar {
  border-bottom: 1px solid #92400e; background: #422006; padding: 10px 16px; max-height: 180px; overflow: auto;
}
.approval-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 0.85rem; }
.approval-item {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; margin-bottom: 6px; font-size: 0.85rem;
}
.approval-item p { margin: 0 0 6px; }
.chat-foot { margin: 8px 0 0; font-size: 0.75rem; }
