:root {
  --bg: #0e1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --border: #2b3442;
  --text: #d7dee8;
  --muted: #8b98a9;
  --accent: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* login */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: 340px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-card h1 { margin: 0; font-size: 20px; text-align: center; }
.login-card .sub { margin: 0 0 8px; text-align: center; color: var(--muted); font-size: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input, .login-card button { font-size: 14px; padding: 10px; border-radius: 8px; }
.login-card input { border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.login-card button { border: none; background: var(--accent); color: #fff; cursor: pointer; font-weight: 600; }
.login-card button:hover { filter: brightness(1.1); }
.error { background: rgba(239,68,68,.15); color: #fca5a5; padding: 8px; border-radius: 8px; font-size: 13px; text-align: center; }

/* topbar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; }
.topbar .actions { display: flex; align-items: center; gap: 12px; }
.link { color: var(--muted); text-decoration: none; font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); display: inline-block; }
.dot.on { background: var(--green); box-shadow: 0 0 8px var(--green); }

/* layout */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "add list" "log log";
  gap: 16px; padding: 16px; max-width: 1400px; margin: 0 auto;
}
.add-panel { grid-area: add; }
.list-panel { grid-area: list; }
.log-panel { grid-area: log; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.panel h2 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.panel h2:nth-of-type(2) { margin-top: 18px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 0 0 8px; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

textarea, input, select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px; font-size: 13px; font-family: inherit; width: 100%;
}
textarea { resize: vertical; font-family: ui-monospace, monospace; }
input { width: auto; }

button {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.danger-ghost { color: #fca5a5; }
button.ghost { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.row { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.chk input { width: auto; }
.msg { font-size: 12px; color: var(--muted); }

.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px; align-items: center;
}
.grid-form input { width: 100%; }
.grid-form button { white-space: nowrap; }

/* table */
.table-wrap { max-height: 420px; overflow: auto; border-radius: 8px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel-2); color: var(--muted); font-weight: 600; z-index: 1; }
tr:hover td { background: rgba(59,130,246,.06); }
.badge { background: var(--panel-2); border-radius: 10px; padding: 1px 8px; font-size: 12px; color: var(--muted); }

.status { padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.s-idle { background: #374151; color: #cbd5e1; }
.s-queued { background: rgba(234,179,8,.2); color: #fde047; }
.s-running { background: rgba(59,130,246,.2); color: #93c5fd; }
.s-success { background: rgba(34,197,94,.2); color: #86efac; }
.s-failed { background: rgba(239,68,68,.2); color: #fca5a5; }

/* log */
.log-panel { display: flex; flex-direction: column; }
#log {
  background: #0a0d12; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; height: 340px; overflow: auto; margin: 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px;
  line-height: 1.5; white-space: pre-wrap; word-break: break-all;
}
.log-filter-row { display: flex; gap: 8px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "add" "list" "log"; }
  .grid-form { grid-template-columns: 1fr 1fr; }
}

/* failure highlight */
tr.row-failed td { background: rgba(239,68,68,.14) !important; }
tr.row-failed td:first-child { box-shadow: inset 4px 0 0 var(--red); }
tr.row-failed:hover td { background: rgba(239,68,68,.24) !important; }
tr.row-running td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
button.logbtn { border-color: var(--border); }
button.logbtn.failed { background: rgba(239,68,68,.25); color: #fecaca; border-color: var(--red); font-weight: 700; }

/* modal */
.hidden { display: none !important; }
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  width: min(860px, 92vw); max-height: 86vh; display: flex; flex-direction: column;
  padding: 16px; box-shadow: 0 24px 80px rgba(0,0,0,.6);
}
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.modal-head #modal-title { font-weight: 700; font-size: 15px; flex: 1; }
.modal-close { margin-left: auto; }
#modal-log {
  background: #0a0d12; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; flex: 1; overflow: auto; margin: 0 0 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px;
  line-height: 1.5; white-space: pre-wrap; word-break: break-all;
  min-height: 320px; max-height: 60vh;
}
.modal-actions { display: flex; gap: 10px; }
