/* tk-devin Web UI — 内部工具风:深色、紧凑、信息密度优先。
 * 配色沿用 taikula 生态设计语言(近黑底 + 信号绿单强调色)。 */

/* 自托管等宽字体(同源资产,public/fonts/);中文由本机已装的等距更纱黑体 SC 等兜底,不自托管。 */
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0a0b0d;
  --panel: #12151a;
  --panel-2: #171b21;
  --line: #22262e;
  --text: #eceef2;
  --dim: #9aa1ac;
  --acc: #3ddc97;
  --acc-ink: #06281c;
  --ok: #3ddc97;
  --warn: #e2c93b;
  --danger: #e2695c;
  --info: #3ddce0;
  --blue: #6fb2ff;
  --font-main: "JetBrains Mono", "等距更纱黑体 SC", "Sarasa Mono SC", "Sarasa Term SC", "PingFang SC", "Microsoft YaHei", ui-monospace, monospace;
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  font-size: 14px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }
.mono { font-family: var(--font-main); }
.dim { color: var(--dim); }
.text-ok { color: var(--ok); }
.text-danger { color: var(--danger); }

/* ---------- 登录屏 ---------- */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box { max-width: 340px; width: 100%; }
.login-title { font-size: 24px; font-weight: 700; color: var(--acc); margin-bottom: 6px; }
.login-hint { color: var(--dim); margin-bottom: 20px; line-height: 1.6; }
#login-form { display: flex; flex-direction: column; gap: 10px; }
#login-password, #login-label {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  font-size: 15px;
}
#login-password::placeholder, #login-label::placeholder { color: var(--dim); opacity: 0.7; }
.login-err { color: var(--danger); margin-top: 12px; font-size: 13px; }

/* ---------- 按钮 ---------- */
.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
}
.btn:hover { border-color: var(--dim); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: rgba(226, 105, 92, 0.12); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ---------- 应用外壳:桌面侧栏 + 顶栏 ---------- */
#app-view {
  display: grid;
  grid-template-columns: 168px 1fr;
  grid-template-rows: 52px 1fr;
  grid-template-areas: "topbar topbar" "nav main";
  height: 100vh;
}
#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: linear-gradient(180deg, #161a20, var(--panel));
  border-bottom: 1px solid var(--line);
}
.topbar-title {
  font-weight: 700;
  color: var(--acc);
  letter-spacing: 0.02em;
}
#topbar .btn { margin-left: auto; }

#nav {
  grid-area: nav;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 8px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
#nav a {
  color: var(--dim);
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 13px;
}
#nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
#nav a.active { color: var(--acc); background: var(--acc-ink); font-weight: 600; }

#view {
  grid-area: main;
  overflow-y: auto;
  padding: 16px;
}

@media (max-width: 760px) {
  #app-view {
    grid-template-columns: 1fr;
    grid-template-rows: 52px auto 1fr;
    grid-template-areas: "topbar" "nav" "main";
  }
  #nav {
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 6px 8px;
  }
  #nav a { flex: none; }
}

/* ---------- 通用卡片/表单 ---------- */
.page { display: flex; flex-direction: column; gap: 18px; max-width: 980px; }
.page h2 { font-size: 16px; font-weight: 600; }
.page h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
}
.inline-form { max-width: 640px; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.field label { font-size: 12px; color: var(--dim); }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  width: 100%;
}
textarea { resize: vertical; min-height: 90px; font-family: var(--font-main); }
.radio-row { display: flex; gap: 16px; }
.radio { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.checkbox-field label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); }
.task-form { display: flex; flex-direction: column; gap: 12px; }
.task-form > button { align-self: flex-start; }
.empty { color: var(--dim); padding: 14px 0; }

/* ---------- 徽章(任务状态 / 心跳失联等) ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-queued { background: #23262d; color: var(--dim); }
.badge-claimed, .badge-preparing { background: #123655; color: var(--blue); }
.badge-running { background: #0e3a3a; color: var(--info); }
.badge-done { background: #123b29; color: var(--ok); }
.badge-needs_input { background: #3a3312; color: var(--warn); }
.badge-failed, .badge-failed_quota { background: #3a1414; color: var(--danger); }
.badge-cancelled { background: #1a1c20; color: #5b6270; }
.badge-account { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.badge-group { display: inline-flex; gap: 4px; flex-wrap: wrap; }

/* ---------- 任务页三栏布局(#nav 为第一栏,这里是列表列 + 详情列) ---------- */
.page-tasks-split {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 1fr;
  gap: 16px;
  height: 100%;
  max-width: none;
}
.task-list-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.task-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--line);
}
.task-list-header h2 { font-size: 15px; }
.task-list-box { flex: 1; overflow-y: auto; padding: 8px; }
.task-detail-col { min-height: 0; overflow-y: auto; }
.task-detail-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 240px;
}
/* 详情内容靠左、不撑满整列宽度,给宽屏右侧留白(阅读行宽) */
.task-detail-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 880px;
}

/* <900px:三栏退化为两态——未选中显示列表(全宽),选中显示详情(全宽) */
@media (max-width: 899px) {
  .page-tasks-split {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    height: auto;
  }
  .task-list-col, .task-detail-col { display: none; }
  .page-tasks-split:not(.task-selected) .task-list-col { display: flex; }
  .page-tasks-split.task-selected .task-detail-col { display: block; }
  .task-detail-content { max-width: none; } /* 窄屏不受限,照旧全宽 */
}
/* ≥900px:列表列已常驻可见,详情内「返回任务列表」链接冗余,隐藏之 */
@media (min-width: 900px) {
  .task-detail-col .back-link { display: none; }
}

/* ---------- 任务列表(紧凑行:徽章 + 标题 + id + 相对时间) ---------- */
.task-list { display: flex; flex-direction: column; gap: 6px; }
.task-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
}
.task-row:hover { border-color: var(--dim); text-decoration: none; }
.task-row.active { border-color: var(--acc); background: var(--acc-ink); }
.task-row-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.task-row-bottom { display: flex; align-items: center; gap: 8px; }
.task-id { color: var(--dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.task-title { font-weight: 600; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-time { margin-left: auto; font-size: 11px; color: var(--dim); white-space: nowrap; }

/* ---------- 任务详情 ---------- */
.back-link { display: inline-block; margin-bottom: 4px; font-size: 13px; }
.detail-header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.detail-header h2 { font-size: 18px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
}
.detail-field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.df-label { font-size: 11px; color: var(--dim); }
.df-value { font-size: 13px; word-break: break-word; }
.prompt-box {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-main);
  font-size: 12px;
  color: var(--text);
  max-height: 320px;
  overflow-y: auto;
}

/* ---------- 执行现场(runner 15s 抓取的 tmux pane 尾部快照) ---------- */
.terminal-tail-header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.terminal-tail-hint { font-size: 11px; white-space: nowrap; }
.terminal-tail-box {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--font-main);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}

/* ---------- 追加指示(向还在运行的会话注入补充要求) ---------- */
.followup-actions { display: flex; justify-content: flex-end; margin-top: 8px; }

/* ---------- 事件时间线 ---------- */
.timeline { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.timeline-item {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  border-left: 2px solid var(--line);
  padding-left: 10px;
}
.tl-time { color: var(--dim); flex: none; }
.tl-transition { display: flex; align-items: center; gap: 6px; }
.tl-arrow { color: var(--dim); }
.tl-null { color: var(--dim); }
.tl-detail { color: var(--dim); flex: 1 1 auto; min-width: 0; word-break: break-word; }

/* ---------- 表格(账号/机器/额度/通知共用) ---------- */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.data-table th, .data-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.data-table th { color: var(--dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table tr:last-child td { border-bottom: none; }
.data-table td:nth-child(2) { white-space: normal; }

/* ---------- 额度利用率横条 ---------- */
.util-cell { display: flex; align-items: center; gap: 8px; min-width: 160px; }
.util-bar { width: 70px; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; flex: none; }
.util-bar-fill { height: 100%; border-radius: 4px; }
.util-ok { background: var(--ok); }
.util-warn { background: var(--warn); }
.util-danger { background: var(--danger); }
.util-pct { font-size: 12px; width: 32px; }
.util-reset { font-size: 11px; white-space: nowrap; }

/* ---------- runner token 一次性回显 ---------- */
.token-box { margin-top: 14px; padding: 12px; border: 1px solid var(--danger); border-radius: 8px; background: rgba(226, 105, 92, 0.08); }
.token-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.token-value { font-size: 15px; word-break: break-all; }

/* ---------- 通知测试结果 ---------- */
.test-results { list-style: none; display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.test-results li { display: flex; gap: 10px; align-items: center; font-size: 13px; }

/* ---------- 轻提示 ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  max-width: 90vw;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 100;
}

/* ---------- 新建任务弹窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 200;
}
.modal-dialog {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.modal-dialog .task-form h2 { font-size: 16px; font-weight: 600; padding-right: 28px; }
.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 9px;
  border-radius: 6px;
}
.modal-close:hover { color: var(--text); background: var(--panel-2); }

/* <900px:弹窗近全屏,底部贴边更贴近原生 App 手感 */
@media (max-width: 899px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-dialog {
    max-width: none;
    width: 100%;
    max-height: 92vh;
    border-radius: 12px 12px 0 0;
  }
}
