:root {
  --navy: #1f3864;
  --blue: #2f5496;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --border: #dfe3ea;
  --gray: #666666;
  --green: #2e7d32;
  --green-bg: #e2f0d9;
  --red: #c0392b;
  --red-bg: #fbeaea;
  --orange: #b9770e;
  --orange-bg: #fdf1df;
  --blue-badge-bg: #dce6f1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  background: var(--bg);
  color: #222;
}

/* ---------- Login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
.login-box {
  background: var(--card-bg);
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  width: 340px;
}
.login-box h1 {
  font-size: 20px;
  color: var(--navy);
  margin: 0 0 4px;
  text-align: center;
}
.login-box .subtitle {
  text-align: center;
  color: var(--gray);
  margin-bottom: 20px;
  font-size: 14px;
}
.login-box label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--gray);
}
.login-box input {
  width: 100%;
  padding: 10px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.login-box button {
  width: 100%;
  padding: 10px;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
}
.alert-error {
  background: var(--red-bg);
  color: var(--red);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--navy);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar h1 { font-size: 18px; margin: 0; }
.user-bar { font-size: 13px; }
.user-bar a { color: #cfe0ff; margin-left: 12px; }

/* ---------- Layout ---------- */
.layout {
  display: flex;
  gap: 16px;
  padding: 20px;
  align-items: flex-start;
}
.left-panel {
  flex: 0 0 420px;
  background: var(--card-bg);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.right-panel {
  flex: 1;
  background: var(--card-bg);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  min-height: 400px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.panel-head h2 { font-size: 16px; margin: 0; color: var(--navy); }

#task-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#task-table th {
  text-align: left;
  color: var(--gray);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding: 6px 4px;
}
#task-table td {
  padding: 8px 4px;
  border-bottom: 1px solid #eee;
}
#task-table tbody tr { cursor: pointer; }
#task-table tbody tr:hover { background: #f7f9fc; }
#task-table tbody tr.selected { background: var(--blue-badge-bg); }

.hint { color: var(--gray); font-size: 14px; }

button {
  font-family: inherit;
}
#btn-new-task, .btn-primary {
  background: var(--navy);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn-secondary {
  background: #eee;
  color: #333;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-planning, .badge-running { background: var(--blue-badge-bg); color: var(--blue); }
.badge-awaiting_plan_review, .badge-awaiting_review { background: var(--orange-bg); color: var(--orange); }
.badge-approved, .badge-completed { background: var(--green-bg); color: var(--green); }
.badge-rejected, .badge-plan_rejected, .badge-halted, .badge-failed { background: var(--red-bg); color: var(--red); }
.badge-pending { background: #f0f0f0; color: #777; }

/* ---------- Task Detail ---------- */
.task-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.task-title-row h2 { margin: 0; font-size: 18px; color: var(--navy); }
.task-meta { color: var(--gray); font-size: 13px; margin-bottom: 16px; }
.task-desc {
  background: #f7f9fc;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 18px;
  white-space: pre-wrap;
}

.plan-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 20px;
  background: #fbfcfe;
}
.plan-box h3 { margin: 0 0 10px; font-size: 14px; color: var(--navy); }
.plan-list { list-style: none; padding: 0; margin: 0 0 12px; }
.plan-list li {
  padding: 6px 0;
  border-bottom: 1px dashed #e4e8ef;
  font-size: 13px;
}
.plan-list li:last-child { border-bottom: none; }
.agent-tag {
  display: inline-block;
  min-width: 90px;
  font-weight: 600;
  color: var(--blue);
  margin-right: 6px;
}

.stage-list { display: flex; flex-direction: column; gap: 12px; }
.stage-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #fdfdfe;
}
.stage-card.status-awaiting_review { border-color: var(--orange); }
.stage-card.status-rejected, .stage-card.status-failed { border-color: var(--red); }
.stage-card.status-approved { border-color: var(--green); }

.stage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.stage-head strong { font-size: 14px; }

.summary, .ai-output {
  white-space: pre-wrap;
  font-size: 13px;
  background: #f7f9fc;
  border-radius: 6px;
  padding: 10px;
  margin: 8px 0;
  max-height: 320px;
  overflow-y: auto;
}

.actions { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.actions button {
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.btn-approve { background: var(--green-bg); color: var(--green); }
.btn-reject { background: var(--red-bg); color: var(--red); }
.btn-regenerate { background: var(--blue-badge-bg); color: var(--blue); }
.btn-retry { background: var(--orange-bg); color: var(--orange); }
.btn-logs, .btn-crawl {
  background: #eee;
  color: #333;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 4px;
}

.logs, .crawl-data {
  font-size: 12px;
  background: #111;
  color: #b6f2b6;
  padding: 10px;
  border-radius: 6px;
  margin-top: 8px;
  max-height: 220px;
  overflow-y: auto;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.log-line.log-warning { color: #ffd479; }
.log-line.log-error { color: #ff8b8b; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  width: 420px;
  max-width: 90vw;
}
.modal-box h2 { margin-top: 0; font-size: 16px; color: var(--navy); }
.modal-box label {
  display: block;
  font-size: 13px;
  color: var(--gray);
  margin-bottom: 12px;
}
.modal-box input, .modal-box textarea, .modal-box select {
  width: 100%;
  padding: 8px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}
