:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #667085;
  --line: #d8ddd5;
  --green: #217a5b;
  --green-dark: #176247;
  --blue: #2563eb;
  --amber: #b45309;
  --red: #b42318;
  --red-bg: #fef3f2;
  --shadow: 0 8px 24px rgba(31, 41, 55, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button, input, select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button:hover { border-color: #9aa7a0; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

button.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

button.primary:hover {
  background: var(--green-dark);
}

button.secondary {
  background: #f8faf9;
}

button.danger {
  background: var(--red-bg);
  border-color: #f3b8b2;
  color: var(--red);
}

button.ghost {
  background: #fff;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}

.app-shell {
  width: min(1400px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1, h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

.subline {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.badge {
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 10px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.badge.ok {
  border-color: #9bd2bd;
  background: #eefaf5;
  color: var(--green);
}

.badge.error {
  border-color: #f3b8b2;
  background: var(--red-bg);
  color: var(--red);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  margin-bottom: 16px;
}

.hidden { display: none !important; }

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 0.8fr);
  gap: 16px;
  margin-bottom: 16px;
}

.controls-panel,
.status-panel,
.jobs-panel,
.log-panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input, select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

input:focus, select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: var(--blue);
}

.button-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(5, minmax(110px, 1fr));
  gap: 10px;
}

.job-detail {
  display: grid;
  gap: 10px;
  margin: 0;
}

.job-detail div {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
}

.job-detail dt {
  color: var(--muted);
  font-size: 13px;
}

.job-detail dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.follow-row {
  margin-top: 14px;
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.follow-row input {
  width: 16px;
  min-height: 16px;
}

.log-panel {
  margin-bottom: 16px;
}

#logOutput {
  margin: 0;
  width: 100%;
  height: 420px;
  overflow: auto;
  padding: 12px;
  border: 1px solid #242b35;
  border-radius: 6px;
  background: #111827;
  color: #d1fae5;
  font: 13px/1.5 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

th, td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

th {
  color: var(--muted);
  font-weight: 600;
}

tbody tr:hover {
  background: #f8faf9;
}

td:last-child,
th:last-child {
  width: 132px;
  text-align: right;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

.row-actions button {
  min-height: 30px;
  padding: 0 9px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(460px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #1f2937;
  color: #fff;
  box-shadow: 0 12px 36px rgba(31, 41, 55, 0.22);
  font-size: 14px;
}

@media (max-width: 980px) {
  .control-grid {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .button-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1400px);
    padding-top: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 23px;
  }

  .auth-panel,
  .form-grid,
  .button-grid {
    grid-template-columns: 1fr;
  }

  #logOutput {
    height: 360px;
  }
}
