:root {
  --bg: #0b0d10;
  --bg-2: #12151b;
  --bg-3: #181c24;
  --line: #2a3140;
  --text: #e8edf5;
  --muted: #8b95a7;
  --ask: #6ea8ff;
  --plan: #e0b34e;
  --agent: #3dd68c;
  --danger: #ff6b6b;
  --radius: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea {
  font: inherit; color: inherit;
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
button { cursor: pointer; }
button.ghost { background: transparent; }
button.icon { width: 40px; padding: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; }

.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: min(420px, 100%); background: var(--bg-2); padding: 28px;
  border: 1px solid var(--line); border-radius: 20px; display: grid; gap: 12px;
}
.login-card h1 { margin: 0; }
.login-card p { margin: 0 0 8px; color: var(--muted); }

.app {
  height: 100dvh; display: grid;
  grid-template-columns: 260px 1fr 300px;
  overflow: hidden;
}
.sidebar, .task-center {
  background: var(--bg-2); border-right: 1px solid var(--line);
  padding: 16px; overflow: auto;
}
.task-center { border-right: 0; border-left: 1px solid var(--line); }
.brand { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.sidebar-section { font-size: 11px; letter-spacing: .12em; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; }
.project-list { display: grid; gap: 6px; }
.project-list button { text-align: left; }
.project-list button.active { border-color: var(--ask); }
.sidebar-actions { display: grid; gap: 8px; margin: 18px 0; }
.sys-status { font-size: 12px; color: var(--muted); display: grid; gap: 4px; }

.main { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto; min-width: 0; min-height: 0; overflow: hidden; }
.topbar {
  display: flex; gap: 12px; align-items: center; padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.topbar h2 { margin: 0; font-size: 16px; }
.modes { margin-left: auto; display: flex; gap: 6px; }
.mode.active[data-mode="ask"] { border-color: var(--ask); color: var(--ask); }
.mode.active[data-mode="plan"] { border-color: var(--plan); color: var(--plan); }
.mode.active[data-mode="agent"] { border-color: var(--agent); color: var(--agent); }
.admin-bar {
  display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 16px;
  border-bottom: 1px solid var(--line); align-items: center;
}
.admin-bar.busy button[data-act] { opacity: .55; pointer-events: none; }
.admin-busy { font-size: 12px; color: var(--plan); }
.msg.log { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.chat-wrap {
  position: relative; min-height: 0; height: 100%;
  display: grid; grid-template-rows: minmax(0, 1fr); overflow: hidden;
}
.chat {
  min-height: 0; height: 100%; overflow: auto; padding: 16px 16px 28px;
  display: flex; flex-direction: column; gap: 12px;
  overflow-anchor: none; -webkit-overflow-scrolling: touch;
}
.msg {
  max-width: 760px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--bg-3); line-height: 1.5; width: fit-content; max-width: min(760px, 100%);
}
.msg.user { margin-left: auto; background: #1d2636; white-space: pre-wrap; }
.msg.system { color: var(--muted); font-size: 13px; white-space: pre-wrap; background: transparent; padding: 4px 2px; }
.msg.assistant { width: 100%; max-width: 760px; background: transparent; padding: 4px 2px; }
.msg.assistant .body { white-space: normal; }
.msg.assistant .body pre {
  overflow: auto; background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; font-size: 13px;
}
.msg.assistant .body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em; background: var(--bg-3); padding: 1px 5px; border-radius: 6px;
}
.msg.assistant .body pre code { background: none; padding: 0; }
.tool-list { display: grid; gap: 4px; margin: 0 0 8px; }
.tool-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted); padding: 4px 0;
}
.tool-ico {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 1.5px solid var(--muted);
}
.tool-row[data-status="run"] .tool-ico {
  border-color: var(--ask); border-top-color: transparent;
  animation: spin .8s linear infinite;
}
.tool-row[data-status="done"] .tool-ico {
  border-color: var(--agent); background: var(--agent);
  box-shadow: inset 0 0 0 2px var(--bg);
}
.tool-row[data-status="error"] .tool-ico { border-color: var(--danger); background: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }
.thought {
  margin: 0 0 10px; color: var(--muted); font-size: 13px;
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; background: var(--bg-2);
}
.thought summary { cursor: pointer; user-select: none; }
.thought-body { white-space: pre-wrap; margin-top: 8px; opacity: .85; }
.caret {
  display: inline-block; width: 7px; height: 14px; margin-left: 2px; vertical-align: text-bottom;
  background: var(--text); animation: blink 1s steps(1) infinite;
}
.msg.assistant:not(.streaming) .caret { display: none; }
@keyframes blink { 50% { opacity: 0; } }
.jump-latest {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  z-index: 4; padding: 7px 14px; border-radius: 999px; font-size: 13px;
  background: var(--bg-3); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.35);
}

.plan-box { padding: 12px 16px; border-top: 1px solid var(--line); background: var(--bg-2); }
.plan-box label { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }

.composer {
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg-2);
}
.composer-tools { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }
#prompt { width: 100%; resize: none; min-height: 72px; }
#send { align-self: end; background: #e8edf5; color: #111; font-weight: 700; }

.task-group { margin-bottom: 16px; }
.task-item { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar, .task-center {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px);
    z-index: 20; transform: translateX(-110%); transition: transform .2s;
  }
  .sidebar.open, .task-center.open { transform: none; }
  .task-center { inset: 0 0 0 auto; transform: translateX(110%); }
  .task-center.open { transform: none; }
}
