:root {
  --bg: #0b0f17;
  --panel: #121826;
  --panel-2: #0f141d;
  --border: #232c3d;
  --text: #e6e9f0;
  --muted: #8b94a7;
  --accent: #4da3ff;
  --green: #34c77b;
  --red: #ff6b6b;
  --gray: #7a8290;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.error { color: var(--red); min-height: 1.2em; }

/* 登录 */
#login { display: flex; align-items: center; justify-content: center; min-height: 90vh; padding: 16px; }
.card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px 22px;
}
.card h1 { margin: 0 0 6px; font-size: 20px; }

input, textarea, select {
  width: 100%; margin: 10px 0;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; font-size: 15px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 1px solid var(--accent); }

button {
  background: var(--accent); color: #06121f; border: 0; border-radius: 10px;
  padding: 11px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
}
button:active { opacity: .8; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 6px 12px; font-weight: 400; }
button.danger { background: var(--red); color: #fff; width: 100%; margin-top: 10px; }

/* 头部 */
header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  background: rgba(11, 15, 23, .92); backdrop-filter: blur(6px);
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; white-space: nowrap; }
.agent-status, .conn { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; min-width: 0; }
#agent-name { overflow: hidden; text-overflow: ellipsis; max-width: 32vw; }
.conn { margin-left: auto; }
.agent-status { margin-left: auto; }
.conn + button { margin-left: 0; }
#logout-btn { margin-left: 6px; white-space: nowrap; padding: 6px 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray); }
.agent-status.online .dot { background: var(--green); }
.agent-status.offline .dot { background: var(--red); }
.conn.connected .dot { background: var(--green); }

main, section, nav, #task-list { max-width: 760px; margin: 0 auto; }

/* 派单区 */
.new-task { padding: 14px; }
.new-task h2 { font-size: 16px; margin: 0 0 4px; }
.new-task .row { display: flex; align-items: center; gap: 10px; }

/* 过滤 tab */
.tabs { display: flex; gap: 8px; padding: 0 14px 10px; }
.tabs button {
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--border); padding: 6px 14px;
  font-size: 13px; font-weight: 400; border-radius: 999px;
}
.tabs button.active { color: var(--text); border-color: var(--accent); }

/* 任务列表 */
#task-list { list-style: none; padding: 0 14px 40px; }
.task {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
}
.task:active { border-color: var(--accent); }
.task-top { display: flex; align-items: center; gap: 8px; }
.task-top time { margin-left: auto; color: var(--muted); font-size: 12px; }
.tid { color: var(--muted); font-size: 12px; }
.task-prompt { margin-top: 6px; font-size: 14px; color: #c8cede; word-break: break-all; }

.pill {
  font-size: 12px; padding: 2px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.pill.running { color: var(--accent); border-color: var(--accent); animation: pulse 1.6s infinite; }
.pill.done { color: var(--green); border-color: var(--green); }
.pill.failed { color: var(--red); border-color: var(--red); }
.pill.canceled { color: var(--gray); }
@keyframes pulse { 50% { opacity: .45; } }

/* 详情抽屉 */
.drawer {
  position: fixed; inset: 0; z-index: 20;
  background: var(--bg);
  padding: 12px 14px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
#detail-prompt {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; margin: 0; white-space: pre-wrap; word-break: break-all;
  font-family: inherit; font-size: 14px;
}
.log {
  flex: 1; min-height: 45vh;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; margin: 0;
  font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-all;
  overflow-y: auto;
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: #1d2740; color: var(--text); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 10px; z-index: 50; max-width: 86vw;
}
