:root {
  --bg: #f2f5f9;
  --panel: #ffffff;
  --panel-2: #eef2f7;
  --border: #d8e0ea;
  --text: #1f2937;
  --muted: #667489;
  --accent: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #b45309;
  --log-bg: #f7f9fc;
}

* { 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;
  background: linear-gradient(160deg, #eaf0fb 0%, #f2f5f9 60%);
}
.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 18px 50px rgba(31,41,55,.14);
}
.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: #fff; 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.08); }
.error { background: #fee2e2; color: #b91c1c; 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;
  box-shadow: 0 1px 4px rgba(31,41,55,.05);
}
.brand { font-weight: 700; font-size: 16px; }
.topbar .actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.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;
  min-width: 0;
  box-shadow: 0 1px 3px rgba(31,41,55,.05);
}
.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: #fff; 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.08); }
button.danger-ghost { color: var(--red); }
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(37,99,235,.05); }
.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: #e2e8f0; color: #475569; }
.s-queued { background: #fef3c7; color: #92400e; }
.s-running { background: #dbeafe; color: #1d4ed8; }
.s-success { background: #dcfce7; color: #166534; }
.s-failed { background: #fee2e2; color: #b91c1c; }

/* progress bar */
.pbar {
  position: relative; width: 120px; height: 16px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.pbar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #bfdbfe, #60a5fa);
  transition: width .3s ease;
}
.pbar-fill.done { background: linear-gradient(90deg, #bbf7d0, #4ade80); }
.pbar-fill.fail { background: linear-gradient(90deg, #fecaca, #f87171); }
.pbar-txt {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #1e293b;
}
.pct-text { font-size: 12px; color: var(--muted); font-weight: 600; }
.pbar-detail {
  margin-top: 4px; font-size: 11px; color: var(--muted);
  max-width: 220px; white-space: normal; line-height: 1.35;
  font-family: ui-monospace, monospace; word-break: break-all;
}
.activity-text {
  font-size: 12px; color: #1d4ed8; font-family: ui-monospace, monospace;
  max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* log */
.log-panel { display: flex; flex-direction: column; }
#log {
  background: var(--log-bg); 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;
  color: #334155;
}
.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: #fef4f4 !important; }
tr.row-failed td:first-child { box-shadow: inset 4px 0 0 var(--red); }
tr.row-failed:hover td { background: #fde8e8 !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: #fee2e2; color: #b91c1c; border-color: var(--red); font-weight: 700; }

/* modal */
.hidden { display: none !important; }
.modal {
  position: fixed; inset: 0; background: rgba(31,41,55,.45);
  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(31,41,55,.28);
}
.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: var(--log-bg); 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; color: #334155;
}
.modal-actions { display: flex; gap: 10px; align-items: center; }

/* 放行相关 */
button.allow {
  background: #0e7490; border-color: #0e7490; color: #fff; font-weight: 600;
}
button.allow:hover { filter: brightness(1.12); }
button.script {
  background: #7c3aed; border-color: #7c3aed; color: #fff; font-weight: 600;
}
button.script:hover { filter: brightness(1.12); }
button.allowbtn {
  border-color: var(--border);
  background: #e0f2fe; color: #0369a1; font-weight: 600;
}
button.allowbtn.done { background: #dcfce7; color: #166534; border-color: var(--green); }
button.allowbtn.failed { background: #fee2e2; color: #b91c1c; border-color: var(--red); }
button.allowbtn:disabled { opacity: .5; }

.a-idle { background: #e2e8f0; color: #475569; }
.a-running { background: #cffafe; color: #0e7490; }
.a-success { background: #dcfce7; color: #166534; }
.a-failed { background: #fee2e2; color: #b91c1c; }
.allow-time { font-size: 10px; color: var(--muted); margin-top: 2px; }

.sel-col { width: 34px; text-align: center; }
.sel-col input { width: auto; cursor: pointer; }

/* settings modal */
.settings-box { width: min(560px, 92vw); }
.settings-grid {
  display: grid; grid-template-columns: 120px 1fr;
  gap: 10px 12px; align-items: center; margin: 6px 0 14px;
}
.settings-grid > label:not(.chk) { color: var(--muted); font-size: 13px; }
.settings-grid input, .settings-grid select, .settings-grid textarea { width: 100%; }
.settings-grid .chk { grid-column: 1 / -1; }
